Index: lib/prefs.js |
=================================================================== |
--- a/lib/prefs.js |
+++ b/lib/prefs.js |
@@ -31,17 +31,20 @@ function init() |
} |
}; |
Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); |
// Add preference change observer |
try |
{ |
branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); |
- onShutdown.add(function() branch.removeObserver("", Prefs)); |
+ onShutdown.add(function() |
+ { |
+ branch.removeObserver("", Prefs); |
+ }); |
} |
catch (e) |
{ |
Cu.reportError(e); |
} |
} |
/** |
@@ -57,40 +60,49 @@ function defineProperty(/**String*/ name |
value = readFunc(branch, name); |
triggerListeners(name); |
} |
catch(e) |
{ |
Cu.reportError(e); |
} |
}; |
- Prefs.__defineGetter__(name, function() value); |
- Prefs.__defineSetter__(name, function(newValue) |
+ |
+ Object.defineProperty(Prefs, name, |
{ |
- if (value == newValue) |
+ enumerable: true, |
+ get: function () |
+ { |
return value; |
+ }, |
+ set: function (newValue) |
+ { |
+ if (value == newValue) |
+ return value; |
- try |
- { |
- ignorePrefChanges = true; |
- writeFunc(branch, name, newValue); |
- value = newValue; |
- Services.prefs.savePrefFile(null); |
- triggerListeners(name); |
+ try |
+ { |
+ ignorePrefChanges = true; |
+ writeFunc(branch, name, newValue); |
+ value = newValue; |
+ Services.prefs.savePrefFile(null); |
+ triggerListeners(name); |
+ } |
+ catch(e) |
+ { |
+ Cu.reportError(e); |
+ } |
+ finally |
+ { |
+ ignorePrefChanges = false; |
+ } |
+ return value; |
} |
- catch(e) |
- { |
- Cu.reportError(e); |
- } |
- finally |
- { |
- ignorePrefChanges = false; |
- } |
- return value; |
}); |
+ |
Prefs["_update_" + name](); |
} |
let listeners = []; |
function triggerListeners(/**String*/ name) |
{ |
for (let i = 0; i < listeners.length; i++) |
{ |
@@ -165,26 +177,47 @@ let Prefs = exports.Prefs = |
let typeMap = |
{ |
boolean: [getBoolPref, setBoolPref], |
number: [getIntPref, setIntPref], |
string: [getCharPref, setCharPref], |
object: [getJSONPref, setJSONPref] |
}; |
-function getIntPref(branch, pref) branch.getIntPref(pref) |
-function setIntPref(branch, pref, newValue) branch.setIntPref(pref, newValue) |
+function getIntPref(branch, pref) |
+{ |
+ return branch.getIntPref(pref); |
+} |
+function setIntPref(branch, pref, newValue) |
+{ |
+ branch.setIntPref(pref, newValue); |
+} |
-function getBoolPref(branch, pref) branch.getBoolPref(pref) |
-function setBoolPref(branch, pref, newValue) branch.setBoolPref(pref, newValue) |
+function getBoolPref(branch, pref) |
+{ |
+ return branch.getBoolPref(pref); |
+} |
+function setBoolPref(branch, pref, newValue) |
+{ |
+ branch.setBoolPref(pref, newValue); |
+} |
-function getCharPref(branch, pref) branch.getComplexValue(pref, Ci.nsISupportsString).data |
+function getCharPref(branch, pref) |
+{ |
+ return branch.getComplexValue(pref, Ci.nsISupportsString).data; |
+} |
function setCharPref(branch, pref, newValue) |
{ |
let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); |
str.data = newValue; |
branch.setComplexValue(pref, Ci.nsISupportsString, str); |
} |
-function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) |
-function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stringify(newValue)) |
+function getJSONPref(branch, pref) |
+{ |
+ return JSON.parse(getCharPref(branch, pref)); |
+} |
+function setJSONPref(branch, pref, newValue) |
+{ |
+ setCharPref(branch, pref, JSON.stringify(newValue)) |
+} |
init(); |