X-Git-Url: https://git.donarmstrong.com/?p=dactyl.git;a=blobdiff_plain;f=common%2Fmodules%2Fprefs.jsm;h=f8e7e403713ddeac9d6e2c2cecd91d87157d3285;hp=13500685dbb10318a2925b33be7ced0a96db680f;hb=9044153cb63835e39b9de8ec4ade237c03e3888a;hpb=70740024f9c028c1fd63e1a1850ab062ff956054 diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index 1350068..f8e7e40 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -4,17 +4,18 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -"use strict"; +/* use strict */ try { Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("prefs", { exports: ["Prefs", "localPrefs", "prefs"], - require: ["services", "util"], - use: ["config", "messages", "template"] + require: ["services", "util"] }, this); +this.lazyRequire("messages", ["_"]); + var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { ORIGINAL: "extensions.dactyl.original.", RESTORE: "extensions.dactyl.restore.", @@ -44,7 +45,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) cleanup: function cleanup(reason) { if (this.defaults != this) - this.defaults.cleanup(); + this.defaults.cleanup(reason); this._observers = {}; if (this.observe) { @@ -62,7 +63,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) this.branches.saved.resetBranch(); } - if (reason == "uninstall" && this == prefs) + if (reason == "uninstall") localPrefs.resetBranch(); } }, @@ -112,7 +113,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) if (!this._observers[pref]) this._observers[pref] = []; - this._observers[pref].push(!strong ? Cu.getWeakReference(callback) : { get: function () callback }); + this._observers[pref].push(!strong ? util.weakReference(callback) : { get: function () callback }); }, /** @@ -198,10 +199,18 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) */ getNames: function getNames(branch) this.branch.getChildList(branch || "", { value: 0 }), + /** + * Returns true if the current branch has the given preference. + * + * @param {string} name The preference name. + * @returns {boolean} + */ + has: function get(name) this.branch.getPrefType(name) != 0, + _checkSafe: function _checkSafe(name, message, value) { let curval = this.get(name, null); - if (this.branches.original.get(name) == null) + if (this.branches.original.get(name) == null && !this.branches.saved.has(name)) this.branches.original.set(name, curval, true); if (arguments.length > 2 && curval === value)