From 32bd47f05368557044dd3441dcaa414b7b009b39 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 12 Jun 2021 09:18:56 -0400 Subject: [PATCH] Force restart at first install for Chromium-based browsers Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1547 The approach used to fix the issue was confirmed working in the following related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1608#issuecomment-856282345 --- src/js/start.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/js/start.js b/src/js/start.js index c98004383..4cbba2220 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -106,16 +106,18 @@ const initializeTabs = async function() { const onVersionReady = function(lastVersion) { if ( lastVersion === vAPI.app.version ) { return; } + vAPI.storage.set({ version: vAPI.app.version }); + + const lastVersionInt = vAPI.app.intFromVersion(lastVersion); + if ( lastVersionInt === 0 ) { return; } + // Since built-in resources may have changed since last version, we // force a reload of all resources. µb.redirectEngine.invalidateResourcesSelfie(); - const lastVersionInt = vAPI.app.intFromVersion(lastVersion); - // https://github.com/LiCybora/NanoDefenderFirefox/issues/196 // Toggle on the blocking of CSP reports by default for Firefox. if ( - lastVersionInt !== 0 && lastVersionInt <= 1031003011 && vAPI.webextFlavor.soup.has('firefox') ) { @@ -123,8 +125,6 @@ const onVersionReady = function(lastVersion) { µb.permanentSwitches.toggle('no-csp-reports', '*', 1); µb.saveHostnameSwitches(); } - - vAPI.storage.set({ version: vAPI.app.version }); }; /******************************************************************************/ @@ -332,7 +332,7 @@ try { // https://github.com/uBlockOrigin/uBlock-issues/issues/1365 // Wait for onCacheSettingsReady() to be fully ready. - await Promise.all([ + const [ , , lastVersion ] = await Promise.all([ µb.loadSelectedFilterLists().then(( ) => { log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`); }), @@ -345,6 +345,7 @@ try { vAPI.storage.get(createDefaultProps()).then(fetched => { log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`); onFirstFetchReady(fetched, adminExtra); + return fetched.version; }), µb.loadUserSettings().then(fetched => { log.info(`User settings ready ${Date.now()-vAPI.T0} ms after launch`); @@ -354,6 +355,12 @@ try { log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`); }), ]); + + // https://github.com/uBlockOrigin/uBlock-issues/issues/1547 + if ( lastVersion === '0.0.0.0' && vAPI.webextFlavor.soup.has('chromium') ) { + vAPI.app.restart(); + return; + } } catch (ex) { console.trace(ex); }