Skip to content

Commit bfa28b9

Browse files
committed
Ensure cache storage is selected before access
Possibly related issue: uBlockOrigin/uBlock-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.
1 parent 1849425 commit bfa28b9

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/js/background.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ const µBlock = { // jshint ignore:line
270270
uiAccentStylesheet: '',
271271
};
272272

273+
µBlock.isReadyPromise = new Promise(resolve => {
274+
µBlock.isReadyResolve = resolve;
275+
});
276+
273277
µBlock.domainFromHostname = domainFromHostname;
274278
µBlock.hostnameFromURI = hostnameFromURI;
275279

src/js/messaging.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,9 @@ const onMessage = function(request, sender, callback) {
15651565
});
15661566

15671567
case 'getLists':
1568-
return getLists(callback);
1568+
return µb.isReadyPromise.then(( ) => {
1569+
getLists(callback);
1570+
});
15691571

15701572
case 'getLocalData':
15711573
return getLocalData().then(localData => {

src/js/start.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ import {
6363

6464
/******************************************************************************/
6565

66-
// Load all: executed once.
67-
68-
(async ( ) => {
69-
// >>>>> start of private scope
70-
71-
/******************************************************************************/
72-
7366
vAPI.app.onShutdown = ( ) => {
7467
staticFilteringReverseLookup.shutdown();
7568
io.updateStop();
@@ -312,10 +305,10 @@ const onHiddenSettingsReady = async ( ) => {
312305
}
313306

314307
// Maybe override default cache storage
315-
const cacheBackend = await cacheStorage.select(
308+
µb.supportStats.cacheBackend = await cacheStorage.select(
316309
µb.hiddenSettings.cacheStorageAPI
317310
);
318-
ubolog(`Backend storage for cache will be ${cacheBackend}`);
311+
ubolog(`Backend storage for cache will be ${µb.supportStats.cacheBackend}`);
319312
};
320313

321314
/******************************************************************************/
@@ -379,6 +372,9 @@ const createDefaultProps = ( ) => {
379372

380373
/******************************************************************************/
381374

375+
(async ( ) => {
376+
// >>>>> start of async/await scope
377+
382378
try {
383379
ubolog(`Start sequence of loading storage-based data ${Date.now()-vAPI.T0} ms after launch`);
384380

@@ -506,5 +502,7 @@ if ( selfieIsValid ) {
506502
}
507503
ubolog(`All ready ${µb.supportStats.allReadyAfter} after launch`);
508504

509-
// <<<<< end of private scope
505+
µb.isReadyResolve();
506+
507+
// <<<<< end of async/await scope
510508
})();

0 commit comments

Comments
 (0)