diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 2a96f71a3..c2f369525 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -78,6 +78,27 @@ vAPI.app = { return version; })(), + intFromVersion: function(s) { + const parts = s.match(/(?:^|\.|b|rc)\d+/g); + if ( parts === null ) { return 0; } + let vint = 0; + for ( let i = 0; i < 4; i++ ) { + const pstr = parts[i] || ''; + let pint; + if ( pstr === '' ) { + pint = 0; + } else if ( pstr.startsWith('.') || pstr.startsWith('b') ) { + pint = parseInt(pstr.slice(1), 10); + } else if ( pstr.startsWith('rc') ) { + pint = parseInt(pstr.slice(2), 10) + 100; + } else { + pint = parseInt(pstr, 10); + } + vint = vint * 1000 + pint; + } + return vint; + }, + restart: function() { browser.runtime.reload(); }, @@ -85,8 +106,10 @@ vAPI.app = { // https://github.com/uBlockOrigin/uBlock-issues/issues/717 // Prevent the extensions from being restarted mid-session. -browser.runtime.onUpdateAvailable.addListener(( ) => { - void 0; +browser.runtime.onUpdateAvailable.addListener(details => { + const toInt = vAPI.app.intFromVersion; + if ( toInt(details.version) > toInt(vAPI.app.version) ) { return; } + browser.runtime.reload(); }); /******************************************************************************/ diff --git a/src/js/start.js b/src/js/start.js index 97b20db13..d5804ccc9 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -181,30 +181,7 @@ const onVersionReady = function(lastVersion) { // force a reload of all resources. µb.redirectEngine.invalidateResourcesSelfie(); - // If unused, just comment out for when we need to compare versions in the - // future. - const intFromVersion = function(s) { - const parts = s.match(/(?:^|\.|b|rc)\d+/g); - if ( parts === null ) { return 0; } - let vint = 0; - for ( let i = 0; i < 4; i++ ) { - const pstr = parts[i] || ''; - let pint; - if ( pstr === '' ) { - pint = 0; - } else if ( pstr.startsWith('.') || pstr.startsWith('b') ) { - pint = parseInt(pstr.slice(1), 10); - } else if ( pstr.startsWith('rc') ) { - pint = parseInt(pstr.slice(2), 10) + 100; - } else { - pint = parseInt(pstr, 10); - } - vint = vint * 1000 + pint; - } - return vint; - }; - - const lastVersionInt = intFromVersion(lastVersion); + const lastVersionInt = vAPI.app.intFromVersion(lastVersion); // https://github.com/uBlockOrigin/uBlock-issues/issues/494 // Remove useless per-site switches. @@ -214,14 +191,6 @@ const onVersionReady = function(lastVersion) { µb.saveHostnameSwitches(); } - // https://github.com/uBlockOrigin/uBlock-issues/issues/212#issuecomment-419741324 - if ( lastVersionInt <= 1015024000 ) { - if ( µb.hiddenSettings.manualUpdateAssetFetchPeriod === 2000 ) { - µb.hiddenSettings.manualUpdateAssetFetchPeriod = 500; - µb.saveHiddenSettings(); - } - } - vAPI.storage.set({ version: vAPI.app.version }); };