Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 22 matching lines...) Expand all Loading... | |
33 defaults.subscriptions_exceptionsurl = "https://easylist-downloads.adblockplus.o rg/exceptionrules.txt"; | 33 defaults.subscriptions_exceptionsurl = "https://easylist-downloads.adblockplus.o rg/exceptionrules.txt"; |
34 defaults.subscriptions_antiadblockurl = "https://easylist-downloads.adblockplus. org/antiadblockfilters.txt"; | 34 defaults.subscriptions_antiadblockurl = "https://easylist-downloads.adblockplus. org/antiadblockfilters.txt"; |
35 defaults.documentation_link = "https://adblockplus.org/redirect?link=%LINK%&lang =%LANG%"; | 35 defaults.documentation_link = "https://adblockplus.org/redirect?link=%LINK%&lang =%LANG%"; |
36 defaults.notificationdata = {}; | 36 defaults.notificationdata = {}; |
37 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on"; | 37 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on"; |
38 defaults.stats_total = {}; | 38 defaults.stats_total = {}; |
39 defaults.show_statsinicon = true; | 39 defaults.show_statsinicon = true; |
40 defaults.show_statsinpopup = true; | 40 defaults.show_statsinpopup = true; |
41 defaults.shouldShowBlockElementMenu = true; | 41 defaults.shouldShowBlockElementMenu = true; |
42 defaults.hidePlaceholders = true; | 42 defaults.hidePlaceholders = true; |
43 defaults.suppress_first_run_page = false; | |
43 | 44 |
44 let Prefs = exports.Prefs = { | 45 let Prefs = exports.Prefs = { |
45 onChanged: new ext._EventTarget(), | 46 onChanged: new ext._EventTarget(), |
46 onLoaded: new ext._EventTarget() | 47 onLoaded: new ext._EventTarget() |
47 }; | 48 }; |
48 | 49 |
49 function keyToPref(key) | 50 function keyToPref(key) |
50 { | 51 { |
51 if (key.indexOf(keyPrefix) != 0) | 52 if (key.indexOf(keyPrefix) != 0) |
52 return null; | 53 return null; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 }, | 87 }, |
87 enumerable: true | 88 enumerable: true |
88 }); | 89 }); |
89 } | 90 } |
90 | 91 |
91 function init() | 92 function init() |
92 { | 93 { |
93 let prefs = Object.keys(defaults); | 94 let prefs = Object.keys(defaults); |
94 prefs.forEach(addPreference); | 95 prefs.forEach(addPreference); |
95 | 96 |
97 let localLoaded = false; | |
98 let managedLoaded = false; | |
99 | |
100 let onProgress = function() | |
kzar
2015/04/08 13:55:45
I found this function name a little confusing when
Sebastian Noack
2015/04/08 15:11:20
Renamed it to checkLoaded, as well for the code in
| |
101 { | |
102 if (!localLoaded || !managedLoaded) | |
103 return; | |
104 | |
105 ext.storage.onChanged.addListener(function(changes) | |
106 { | |
107 for (let key in changes) | |
108 { | |
109 let pref = keyToPref(key); | |
110 if (pref && pref in defaults) | |
111 { | |
112 let change = changes[key]; | |
113 if ("newValue" in change && change.newValue != defaults[pref]) | |
114 overrides[pref] = change.newValue; | |
115 else | |
116 delete overrides[pref]; | |
117 | |
118 Prefs.onChanged._dispatch(pref); | |
119 } | |
120 } | |
121 }); | |
122 | |
123 Prefs.onLoaded._dispatch(); | |
124 }; | |
125 | |
96 // Migrate preferences for users updating from old versions. | 126 // Migrate preferences for users updating from old versions. |
97 // TODO: Remove the migration code after a few releases. | 127 // TODO: Remove the migration code after a few releases. |
98 ext.storage.migratePrefs({ | 128 ext.storage.migratePrefs({ |
99 map: function(key, value) | 129 map: function(key, value) |
100 { | 130 { |
101 if (key in defaults) | 131 if (key in defaults) |
102 { | 132 { |
103 if (key != "currentVersion") | 133 if (key != "currentVersion") |
104 { | 134 { |
105 try | 135 try |
(...skipping 12 matching lines...) Expand all Loading... | |
118 return null; | 148 return null; |
119 }, | 149 }, |
120 | 150 |
121 done: function() | 151 done: function() |
122 { | 152 { |
123 ext.storage.get(prefs.map(prefToKey), function(items) | 153 ext.storage.get(prefs.map(prefToKey), function(items) |
124 { | 154 { |
125 for (let key in items) | 155 for (let key in items) |
126 overrides[keyToPref(key)] = items[key]; | 156 overrides[keyToPref(key)] = items[key]; |
127 | 157 |
128 ext.storage.onChanged.addListener(function(changes) | 158 localLoaded = true; |
129 { | 159 onProgress(); |
130 for (let key in changes) | |
131 { | |
132 let pref = keyToPref(key); | |
133 if (pref && pref in defaults) | |
134 { | |
135 let change = changes[key]; | |
136 if ("newValue" in change && change.newValue != defaults[pref]) | |
137 overrides[pref] = change.newValue; | |
138 else | |
139 delete overrides[pref]; | |
140 | |
141 Prefs.onChanged._dispatch(pref); | |
142 } | |
143 } | |
144 }); | |
145 | |
146 Prefs.onLoaded._dispatch(); | |
147 }); | 160 }); |
148 } | 161 } |
149 }); | 162 }); |
163 | |
164 if (require("info").platform == "chromium" && "managed" in chrome.storage) | |
165 { | |
166 chrome.storage.managed.get(null, function(items) | |
167 { | |
168 for (let key in items) | |
169 defaults[key] = items[key]; | |
170 | |
171 managedLoaded = true; | |
172 onProgress(); | |
173 }); | |
174 } | |
175 else | |
176 { | |
177 managedLoaded = true; | |
178 onProgress(); | |
179 } | |
150 } | 180 } |
151 | 181 |
152 init(); | 182 init(); |
OLD | NEW |