| Index: lib/prefs.js |
| diff --git a/lib/prefs.js b/lib/prefs.js |
| index 7686f83f462e7f19f406583e3bea424c144a3f43..0f77b584b4c37e935f2748432746c74233fcd249 100644 |
| --- a/lib/prefs.js |
| +++ b/lib/prefs.js |
| @@ -259,32 +259,17 @@ function savePref(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; |
| + // Saving one browser.storage value causes all others to be saved as well on |
| + // Gecko. Until that is rectified[1] we need to avoid saving the ad counter |
| + // using browser.storage too often, since the filters data is saved as a |
| + // side-effect. We do this by using localStorage instead, only updating the |
| + // value saved in browser.storage when the extension first initializes. |
| + // Note: This workaround is sub-optimal since if the user clears browser data |
| + // localStorage is cleared. |
| + // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1277612 |
| 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(); |
| + window.localStorage.setItem("blocked_total", overrides.blocked_total); |
| }); |
| } |
| @@ -326,6 +311,20 @@ function init() |
| for (let key in items) |
| overrides[keyToPref(key)] = items[key]; |
| + if (require("info").platform == "gecko") |
| + { |
| + let blockedTotal = window.localStorage.getItem("blocked_total"); |
| + if (typeof blockedTotal == "string") |
| + { |
| + blockedTotal = JSON.parse(blockedTotal); |
| + if (blockedTotal > overrides.blocked_total) |
| + { |
| + overrides.blocked_total = blockedTotal; |
| + savePref("blocked_total"); |
| + } |
| + } |
| + } |
| + |
| resolve(); |
| }); |
| }); |