Index: lib/prefs.js |
=================================================================== |
--- a/lib/prefs.js |
+++ b/lib/prefs.js |
@@ -233,16 +233,53 @@ function keyToPref(key) |
return key.substr(keyPrefix.length); |
} |
function prefToKey(pref) |
{ |
return keyPrefix + pref; |
} |
+function savePref(pref) |
+{ |
+ ext.storage.set(prefToKey(pref), overrides[pref]); |
+} |
+ |
+let customSave = new Map(); |
+if (require("info").platform == "gecko") |
+{ |
+ // Saving one storage value causes all others to be saved as well on Gecko. |
+ // Make sure that updating ad counter doesn't cause the filters data to be |
+ // saved frequently as a side-effect. |
+ const MIN_UPDATE_INTERVAL = 60 * 1000; |
+ let lastUpdate = -MIN_UPDATE_INTERVAL; |
+ let updateScheduled = false; |
+ customSave.set("blocked_total", pref => |
+ { |
+ if (updateScheduled) |
+ return; |
+ |
+ let callback = () => |
+ { |
+ lastUpdate = performance.now(); |
+ updateScheduled = false; |
+ savePref(pref); |
+ }; |
+ |
+ let timeElapsed = performance.now() - lastUpdate; |
+ if (timeElapsed < MIN_UPDATE_INTERVAL) |
+ { |
+ setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed); |
+ updateScheduled = true; |
+ } |
+ else |
+ callback(); |
+ }); |
+} |
+ |
function addPreference(pref) |
{ |
Object.defineProperty(Prefs, pref, { |
get() { return (pref in overrides ? overrides : defaults)[pref]; }, |
set(value) |
{ |
let defaultValue = defaults[pref]; |
@@ -252,17 +289,17 @@ function addPreference(pref) |
if (value == defaultValue) |
{ |
delete overrides[pref]; |
ext.storage.remove(prefToKey(pref)); |
} |
else |
{ |
overrides[pref] = value; |
- ext.storage.set(prefToKey(pref), value); |
+ (customSave.get(pref) || savePref)(pref); |
} |
}, |
enumerable: true |
}); |
} |
function init() |
{ |