mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-24 10:45:46 +01:00
Save option restore data until add-on is disabled. Cleanup preferences on uninstall.
This commit is contained in:
@@ -78,6 +78,8 @@ var Option = Class("Option", {
|
||||
this.globalValue = this.defaultValue;
|
||||
},
|
||||
|
||||
magicalProperties: Set(["cleanupValue"]),
|
||||
|
||||
/**
|
||||
* @property {string} This option's description, as shown in :listoptions.
|
||||
*/
|
||||
@@ -91,6 +93,13 @@ var Option = Class("Option", {
|
||||
|
||||
get isDefault() this.stringValue === this.stringDefaultValue,
|
||||
|
||||
/** @property {value} The value to reset this option to at cleanup time. */
|
||||
get cleanupValue() options.cleanupPrefs.get(this.name),
|
||||
set cleanupValue(value) {
|
||||
if (options.cleanupPrefs.get(this.name) == null)
|
||||
options.cleanupPrefs.set(this.name, value);
|
||||
},
|
||||
|
||||
/** @property {value} The option's global value. @see #scope */
|
||||
get globalValue() { try { return options.store.get(this.name, {}).value; } catch (e) { util.reportError(e); throw e; } },
|
||||
set globalValue(val) { options.store.set(this.name, { value: val, time: Date.now() }); },
|
||||
@@ -282,8 +291,6 @@ var Option = Class("Option", {
|
||||
*/
|
||||
scope: 1, // Option.SCOPE_GLOBAL // XXX set to BOTH by default someday? - kstep
|
||||
|
||||
cleanupValue: null,
|
||||
|
||||
/**
|
||||
* @property {function(CompletionContext, Args)} This option's completer.
|
||||
* @see CompletionContext
|
||||
@@ -817,7 +824,7 @@ var Options = Module("options", {
|
||||
cleanup: function cleanup() {
|
||||
for (let opt in this)
|
||||
if (opt.cleanupValue != null)
|
||||
opt.value = opt.parse(opt.cleanupValue);
|
||||
opt.stringValue = opt.cleanupValue;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -883,6 +890,13 @@ var Options = Module("options", {
|
||||
setPref: deprecated("prefs.set", function setPref() prefs.set.apply(prefs, arguments)),
|
||||
withContext: deprecated("prefs.withContext", function withContext() prefs.withContext.apply(prefs, arguments)),
|
||||
|
||||
cleanupPrefs: Class.memoize(function () localPrefs.Branch("cleanup.option.")),
|
||||
|
||||
cleanup: function cleanup(reason) {
|
||||
if (~["disable", "uninstall"].indexOf(reason))
|
||||
this.cleanupPrefs.resetBranch();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the option with *name* in the specified *scope*.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user