own page load microopt: reduce blocking on prefs
postpone noncritical init stuff to window.load because first access to chrome API takes time to initialize API bindings
This commit is contained in:
parent
eccabb8f27
commit
4eae87e606
17
prefs.js
17
prefs.js
|
@ -146,8 +146,19 @@ var prefs = new function Prefs() {
|
|||
} else {
|
||||
value = defaultValue;
|
||||
}
|
||||
this.set(key, value, {noBroadcast: true});
|
||||
if (BG == window) {
|
||||
// when in bg page, .set() will write to localStorage
|
||||
this.set(key, value, {noBroadcast: true, noSync: true});
|
||||
} else {
|
||||
values[key] = value;
|
||||
defineReadonlyProperty(this.readOnlyValues, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// any access to chrome API takes time due to initialization of bindings
|
||||
let lazyInit = () => {
|
||||
window.removeEventListener('load', lazyInit);
|
||||
lazyInit = null;
|
||||
|
||||
getSync().get('settings', ({settings: synced} = {}) => {
|
||||
if (synced) {
|
||||
|
@ -194,6 +205,10 @@ var prefs = new function Prefs() {
|
|||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('load', lazyInit);
|
||||
return;
|
||||
|
||||
function doBroadcast() {
|
||||
const affects = {all: 'disableAll' in broadcastPrefs};
|
||||
|
|
Loading…
Reference in New Issue
Block a user