diff --git a/background/background.js b/background/background.js index cab15047..398265e6 100644 --- a/background/background.js +++ b/background/background.js @@ -39,7 +39,6 @@ if ('commands' in chrome) { // ************************************************************************* // set the default icon displayed after a tab is created until webNavigation kicks in prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {})); -updateIcon({id: undefined}, {}); // ************************************************************************* { @@ -59,24 +58,6 @@ updateIcon({id: undefined}, {}); browserUIlanguage: chrome.i18n.getUILanguage(), }); } - // TODO: remove in the future - // embed style digests - chrome.storage.local.get(null, data => { - const digestKeys = Object.keys(data).filter(key => key.startsWith('originalDigest')); - if (!digestKeys.length) { - return; - } - chrome.storage.local.remove(digestKeys); - getStyles().then(styles => { - for (const style of styles) { - const digest = data['originalDigest' + style.id]; - if (!style.originalDigest && digest) { - style.originalDigest = digest; - dbExec('put', style); - } - } - }); - }); }; // bind for 60 seconds max and auto-unbind if it's a normal run chrome.runtime.onInstalled.addListener(onInstall); @@ -156,7 +137,11 @@ contextMenus = Object.assign({ // ************************************************************************* // [re]inject content scripts -{ +window.addEventListener('storageReady', function _() { + window.removeEventListener('storageReady', _); + + updateIcon({id: undefined}, {}); + const NTP = 'chrome://newtab/'; const PING = {method: 'ping'}; const ALL_URLS = ''; @@ -203,8 +188,7 @@ contextMenus = Object.assign({ setTimeout(pingCS, 0, cs, tab)); } })); -} - +}); // ************************************************************************* diff --git a/background/storage.js b/background/storage.js index f9e88609..84495745 100644 --- a/background/storage.js +++ b/background/storage.js @@ -84,25 +84,32 @@ var chromeSync = { // eslint-disable-next-line no-var var dbExec = dbExecIndexedDB; +dbExec.initialized = false; // we use chrome.storage.local fallback if IndexedDB doesn't save data, // which, once detected on the first run, is remembered in chrome.storage.local // for reliablility and in localStorage for fast synchronous access // (FF may block localStorage depending on its privacy options) do { + const done = () => { + getStyles().then(() => { + dbExec.initialized = true; + window.dispatchEvent(new Event('storageReady')); + }); + }; const fallback = () => { dbExec = dbExecChromeStorage; chromeLocal.set({dbInChromeStorage: true}); localStorage.dbInChromeStorage = 'true'; ignoreChromeError(); - getStyles(); + done(); }; const fallbackSet = localStorage.dbInChromeStorage; if (fallbackSet === 'true' || !tryCatch(() => indexedDB)) { fallback(); break; } else if (fallbackSet === 'false') { - getStyles(); + done(); break; } chromeLocal.get('dbInChromeStorage') @@ -121,7 +128,7 @@ do { if (result === 'ok') { chromeLocal.set({dbInChromeStorage: false}); localStorage.dbInChromeStorage = 'false'; - getStyles(); + done(); } else { fallback(); } diff --git a/js/prefs.js b/js/prefs.js index 7b021556..7938a475 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -241,6 +241,13 @@ var prefs = new function Prefs() { return; function doBroadcast() { + if (BG && BG === window && !BG.dbExec.initialized) { + window.addEventListener('storageReady', function _() { + window.removeEventListener('storageReady', _); + doBroadcast(); + }); + return; + } const affects = { all: 'disableAll' in broadcastPrefs || 'exposeIframes' in broadcastPrefs,