Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/prefs.js

Issue 6443935886999552: Issue 2444 - Configure default prefs in JSON (Closed)
Patch Set: Created May 1, 2015, 8:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/prefs.js
===================================================================
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -16,31 +16,28 @@
{
// Load default preferences and set up properties for them
let defaultBranch = Services.prefs.getDefaultBranch(branchName);
- let scope =
+
+ let request = new XMLHttpRequest();
+ request.open("GET", addonRoot + "defaults/prefs.json", false);
Felix Dahlke 2015/05/01 20:36:52 Not really happy with using a sync request here -
+ request.responseType = "json";
+ request.send();
+
+ let defaults = request.response.defaults;
+ for (let pref in defaults)
{
- pref: function(pref, value, preconfigurable)
+ let value = defaults[pref];
+ let [getter, setter] = typeMap[typeof value];
+ if (request.response.preconfigurable.indexOf(pref) != -1)
{
- if (pref.substr(0, branchName.length) != branchName)
+ try
{
- Cu.reportError(new Error("Ignoring default preference " + pref + ", wrong branch."));
- return;
+ value = getter(preconfiguredBranch, pref);
}
- pref = pref.substr(branchName.length);
-
- let [getter, setter] = typeMap[typeof value];
- if (preconfigurable)
- {
- try
- {
- value = getter(preconfiguredBranch, pref);
- }
- catch (e) {}
- }
- setter(defaultBranch, pref, value);
- defineProperty(pref, false, getter, setter);
+ catch (e) {}
}
- };
- Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope);
+ setter(defaultBranch, pref, value);
+ defineProperty(pref, false, getter, setter);
+ }
// Add preference change observer
try
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld