enqueue stuff dependent on DB decision
This commit is contained in:
parent
53aa239da3
commit
09010c20a6
|
@ -39,7 +39,6 @@ if ('commands' in chrome) {
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// set the default icon displayed after a tab is created until webNavigation kicks in
|
// set the default icon displayed after a tab is created until webNavigation kicks in
|
||||||
prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {}));
|
prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {}));
|
||||||
updateIcon({id: undefined}, {});
|
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
{
|
{
|
||||||
|
@ -59,24 +58,6 @@ updateIcon({id: undefined}, {});
|
||||||
browserUIlanguage: chrome.i18n.getUILanguage(),
|
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
|
// bind for 60 seconds max and auto-unbind if it's a normal run
|
||||||
chrome.runtime.onInstalled.addListener(onInstall);
|
chrome.runtime.onInstalled.addListener(onInstall);
|
||||||
|
@ -156,7 +137,11 @@ contextMenus = Object.assign({
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// [re]inject content scripts
|
// [re]inject content scripts
|
||||||
{
|
window.addEventListener('storageReady', function _() {
|
||||||
|
window.removeEventListener('storageReady', _);
|
||||||
|
|
||||||
|
updateIcon({id: undefined}, {});
|
||||||
|
|
||||||
const NTP = 'chrome://newtab/';
|
const NTP = 'chrome://newtab/';
|
||||||
const PING = {method: 'ping'};
|
const PING = {method: 'ping'};
|
||||||
const ALL_URLS = '<all_urls>';
|
const ALL_URLS = '<all_urls>';
|
||||||
|
@ -203,8 +188,7 @@ contextMenus = Object.assign({
|
||||||
setTimeout(pingCS, 0, cs, tab));
|
setTimeout(pingCS, 0, cs, tab));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
});
|
||||||
|
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
|
|
||||||
|
|
|
@ -84,25 +84,32 @@ var chromeSync = {
|
||||||
|
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
var dbExec = dbExecIndexedDB;
|
var dbExec = dbExecIndexedDB;
|
||||||
|
dbExec.initialized = false;
|
||||||
|
|
||||||
// we use chrome.storage.local fallback if IndexedDB doesn't save data,
|
// 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
|
// which, once detected on the first run, is remembered in chrome.storage.local
|
||||||
// for reliablility and in localStorage for fast synchronous access
|
// for reliablility and in localStorage for fast synchronous access
|
||||||
// (FF may block localStorage depending on its privacy options)
|
// (FF may block localStorage depending on its privacy options)
|
||||||
do {
|
do {
|
||||||
|
const done = () => {
|
||||||
|
getStyles().then(() => {
|
||||||
|
dbExec.initialized = true;
|
||||||
|
window.dispatchEvent(new Event('storageReady'));
|
||||||
|
});
|
||||||
|
};
|
||||||
const fallback = () => {
|
const fallback = () => {
|
||||||
dbExec = dbExecChromeStorage;
|
dbExec = dbExecChromeStorage;
|
||||||
chromeLocal.set({dbInChromeStorage: true});
|
chromeLocal.set({dbInChromeStorage: true});
|
||||||
localStorage.dbInChromeStorage = 'true';
|
localStorage.dbInChromeStorage = 'true';
|
||||||
ignoreChromeError();
|
ignoreChromeError();
|
||||||
getStyles();
|
done();
|
||||||
};
|
};
|
||||||
const fallbackSet = localStorage.dbInChromeStorage;
|
const fallbackSet = localStorage.dbInChromeStorage;
|
||||||
if (fallbackSet === 'true' || !tryCatch(() => indexedDB)) {
|
if (fallbackSet === 'true' || !tryCatch(() => indexedDB)) {
|
||||||
fallback();
|
fallback();
|
||||||
break;
|
break;
|
||||||
} else if (fallbackSet === 'false') {
|
} else if (fallbackSet === 'false') {
|
||||||
getStyles();
|
done();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
chromeLocal.get('dbInChromeStorage')
|
chromeLocal.get('dbInChromeStorage')
|
||||||
|
@ -121,7 +128,7 @@ do {
|
||||||
if (result === 'ok') {
|
if (result === 'ok') {
|
||||||
chromeLocal.set({dbInChromeStorage: false});
|
chromeLocal.set({dbInChromeStorage: false});
|
||||||
localStorage.dbInChromeStorage = 'false';
|
localStorage.dbInChromeStorage = 'false';
|
||||||
getStyles();
|
done();
|
||||||
} else {
|
} else {
|
||||||
fallback();
|
fallback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,6 +241,13 @@ var prefs = new function Prefs() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
function doBroadcast() {
|
function doBroadcast() {
|
||||||
|
if (BG && BG === window && !BG.dbExec.initialized) {
|
||||||
|
window.addEventListener('storageReady', function _() {
|
||||||
|
window.removeEventListener('storageReady', _);
|
||||||
|
doBroadcast();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const affects = {
|
const affects = {
|
||||||
all: 'disableAll' in broadcastPrefs
|
all: 'disableAll' in broadcastPrefs
|
||||||
|| 'exposeIframes' in broadcastPrefs,
|
|| 'exposeIframes' in broadcastPrefs,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user