Ensure cache storage is selected before access

Possibly related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2136

Also reported internally, steps to reproduce the issue fixed here:

- Open uBO's dashboard through 3-dot > Add-ons > uBO > Settings
- Bring forth "Filter lists" pane
  We want the tab to be already opened at next launch
- Quit Firefox for Android
- Launch Firefox for Android

Result:

Very long launch time, lists marked as out of date.
This commit is contained in:
Raymond Hill 2023-12-10 12:33:51 -05:00
parent 184942503f
commit bfa28b960e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 15 additions and 11 deletions

View File

@ -270,6 +270,10 @@ const µBlock = { // jshint ignore:line
uiAccentStylesheet: '',
};
µBlock.isReadyPromise = new Promise(resolve => {
µBlock.isReadyResolve = resolve;
});
µBlock.domainFromHostname = domainFromHostname;
µBlock.hostnameFromURI = hostnameFromURI;

View File

@ -1565,7 +1565,9 @@ const onMessage = function(request, sender, callback) {
});
case 'getLists':
return getLists(callback);
return µb.isReadyPromise.then(( ) => {
getLists(callback);
});
case 'getLocalData':
return getLocalData().then(localData => {

View File

@ -63,13 +63,6 @@ import {
/******************************************************************************/
// Load all: executed once.
(async ( ) => {
// >>>>> start of private scope
/******************************************************************************/
vAPI.app.onShutdown = ( ) => {
staticFilteringReverseLookup.shutdown();
io.updateStop();
@ -312,10 +305,10 @@ const onHiddenSettingsReady = async ( ) => {
}
// Maybe override default cache storage
const cacheBackend = await cacheStorage.select(
µb.supportStats.cacheBackend = await cacheStorage.select(
µb.hiddenSettings.cacheStorageAPI
);
ubolog(`Backend storage for cache will be ${cacheBackend}`);
ubolog(`Backend storage for cache will be ${µb.supportStats.cacheBackend}`);
};
/******************************************************************************/
@ -379,6 +372,9 @@ const createDefaultProps = ( ) => {
/******************************************************************************/
(async ( ) => {
// >>>>> start of async/await scope
try {
ubolog(`Start sequence of loading storage-based data ${Date.now()-vAPI.T0} ms after launch`);
@ -506,5 +502,7 @@ if ( selfieIsValid ) {
}
ubolog(`All ready ${µb.supportStats.allReadyAfter} after launch`);
// <<<<< end of private scope
µb.isReadyResolve();
// <<<<< end of async/await scope
})();