From 7ae68c8d7db188bc6f20e61fc0172297ceb32eeb Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 24 Jul 2018 09:17:18 -0400 Subject: [PATCH] fix https://github.com/uBlockOrigin/uBlock-issues/issues/144 --- src/js/messaging.js | 20 +++++++++++++------- src/js/storage.js | 14 +++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index 2e661129a..b1e0d85e4 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -792,15 +792,21 @@ var restoreUserData = function(request) { vAPI.localStorage.removeItem('immediateHiddenSettings'); }; +// Remove all stored data but keep global counts, people can become +// quite attached to numbers + var resetUserData = function() { - vAPI.cacheStorage.clear(); - vAPI.storage.clear(); + let count = 3; + let countdown = ( ) => { + count -= 1; + if ( count === 0 ) { + vAPI.app.restart(); + } + }; + vAPI.cacheStorage.clear(countdown); // 1 + vAPI.storage.clear(countdown); // 2 + µb.saveLocalSettings(countdown); // 3 vAPI.localStorage.removeItem('immediateHiddenSettings'); - - // Keep global counts, people can become quite attached to numbers - µb.saveLocalSettings(); - - vAPI.app.restart(); }; /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index 7a48ae3b2..397cb77a0 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2014-2018 Raymond Hill + Copyright (C) 2014-present Raymond Hill This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -52,17 +52,17 @@ /******************************************************************************/ µBlock.saveLocalSettings = (function() { - var saveAfter = 4 * 60 * 1000; + let saveAfter = 4 * 60 * 1000; - var save = function() { + let save = function(callback) { this.localSettingsLastSaved = Date.now(); - vAPI.storage.set(this.localSettings); + vAPI.storage.set(this.localSettings, callback); }; - var onTimeout = function() { - var µb = µBlock; + let onTimeout = ( ) => { + let µb = µBlock; if ( µb.localSettingsLastModified > µb.localSettingsLastSaved ) { - save.call(µb); + µb.saveLocalSettings(); } vAPI.setTimeout(onTimeout, saveAfter); };