simple-prefs
Experimental
The simple-prefs
module lets you easily and persistently store preferences
across application restarts, which can be configured by users in the
Add-ons Manager.
Introduction
With the simple preferences module you can store booleans, integers, and string values.
Inline Options & Default Values
In order to have a options.xul
(for inline options) generated, or a
defaults/preferences/prefs.js
for default preferences, you will need to
define the preferences in your package.json
, like so:
{
"fullName": "Example Add-on",
...
"preferences": [{
"name": "somePreference",
"title": "Some preference title",
"type": "string",
"value": "this is the default string value"
}]
}
API Reference
Functions
on(prefName, listener)
experimental Registers an event listener
that will be called when a preference is changed.
Example:
function onPrefChange(prefName) {
console.log("The " + prefName + " preference changed.");
}
require("simple-prefs").on("somePreference", onPrefChange);
require("simple-prefs").on("someOtherPreference", onPrefChange);
prefName : String
The name of the preference to watch for changes.
listener : Function
The listener function that processes the event.
removeListener(prefName, listener)
experimental Unregisters an event listener
for the specified preference.
prefName : String
The name of the preference to watch for changes.
listener : Function
The listener function that processes the event.
Properties
prefs : object
experimental A persistent object private to your add-on. Properties with boolean, number, and string values will be persisted in the Mozilla preferences system.