enqueue stuff dependent on DB decision

This commit is contained in:
tophf 2017-09-03 21:25:19 +03:00
parent 53aa239da3
commit 09010c20a6
3 changed files with 23 additions and 25 deletions

View File

@ -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 = '<all_urls>';
@ -203,8 +188,7 @@ contextMenus = Object.assign({
setTimeout(pingCS, 0, cs, tab));
}
}));
}
});
// *************************************************************************

View File

@ -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();
}

View File

@ -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,