Be prepared to deal with failure to read user settings

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/507
This commit is contained in:
Raymond Hill 2019-04-03 13:18:47 -03:00
parent 48ac4b21c6
commit 1a7a3298e2
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 13 additions and 11 deletions

View File

@ -296,6 +296,13 @@ const onSystemSettingsReady = function(fetched) {
const onFirstFetchReady = function(fetched) { const onFirstFetchReady = function(fetched) {
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`); log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
// https://github.com/uBlockOrigin/uBlock-issues/issues/507
// Firefox-specific: somehow `fetched` is undefined under certain
// circumstances even though we asked to load with default values.
if ( fetched instanceof Object === false ) {
fetched = createDefaultProps();
}
// https://github.com/gorhill/uBlock/issues/747 // https://github.com/gorhill/uBlock/issues/747
µb.firstInstall = fetched.version === '0.0.0.0'; µb.firstInstall = fetched.version === '0.0.0.0';
@ -331,11 +338,7 @@ const fromFetch = function(to, fetched) {
} }
}; };
/******************************************************************************/ const createDefaultProps = function() {
const onSelectedFilterListsReady = function() {
log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
const fetchableProps = { const fetchableProps = {
'commandShortcuts': [], 'commandShortcuts': [],
'compiledMagic': 0, 'compiledMagic': 0,
@ -361,12 +364,10 @@ const onSelectedFilterListsReady = function() {
'selfieMagic': 0, 'selfieMagic': 0,
'version': '0.0.0.0' 'version': '0.0.0.0'
}; };
toFetch(µb.localSettings, fetchableProps); toFetch(µb.localSettings, fetchableProps);
toFetch(µb.userSettings, fetchableProps); toFetch(µb.userSettings, fetchableProps);
toFetch(µb.restoreBackupSettings, fetchableProps); toFetch(µb.restoreBackupSettings, fetchableProps);
return fetchableProps;
vAPI.storage.get(fetchableProps, onFirstFetchReady);
}; };
/******************************************************************************/ /******************************************************************************/
@ -395,9 +396,10 @@ const onAdminSettingsRestored = function() {
onHiddenSettingsReady() onHiddenSettingsReady()
), ),
µb.loadSelectedFilterLists(), µb.loadSelectedFilterLists(),
]).then(( ) => ]).then(( ) => {
onSelectedFilterListsReady() log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
); vAPI.storage.get(createDefaultProps(), onFirstFetchReady);
});
}; };
/******************************************************************************/ /******************************************************************************/