Confirmed users
146
edits
(Created page with "= Addon Data Directory = Addons may want to store settings or other data on the local computer. In the past, add-ons would use preferences or an arbitrary location on the us...") |
|||
| Line 2: | Line 2: | ||
Addons may want to store settings or other data on the local computer. In the past, add-ons would use preferences or an arbitrary location on the user's filesystem. [https://bugzilla.mozilla.org/show_bug.cgi?id=872980 Preferences are less than ideal], so each Addon object should provide built-in helpers to access a directory specific to it. Then the addon's internal code can refer to the filesystem in a common location. | Addons may want to store settings or other data on the local computer. In the past, add-ons would use preferences or an arbitrary location on the user's filesystem. [https://bugzilla.mozilla.org/show_bug.cgi?id=872980 Preferences are less than ideal], so each Addon object should provide built-in helpers to access a directory specific to it. Then the addon's internal code can refer to the filesystem in a common location. | ||
== Option 1: Direct access to a nsIFile object == | |||
<pre> | |||
get dataDirectory() { | |||
try { | |||
return FileUtils.getFile(KEY_PROFILEDIR, ["extension-data", this.id], false); | |||
} | |||
catch(e) { | |||
return null; | |||
} | |||
}, | |||
</pre> | |||
We may just want to expose an Addon.dataDirectory property. This property points to a folder which is not initially guaranteed to exist. (Unless an add-on demands it, we don't need to create it.) Add-on developers can then either migrate existing files to this directory. They can also create SQLite databases, JSON files, and other settings there. | |||
== Option 2: Indirect access through friendly API's == | |||
We may create the data directory for an add-on, but expose a special Addon.localData API with various methods (.json, .getDBConnection(dbName), etc) for addon developers. | |||