From c8c2e11d091c43434e0541bd3479d9ef3c868ef0 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 6 Sep 2019 13:03:06 -0400 Subject: [PATCH] Prevent reload if updated version is higher than current Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/717 Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/717#issuecomment-528921730 --- platform/chromium/vapi-background.js | 27 +++++++++++++++++++++-- src/js/start.js | 33 +--------------------------- 2 files changed, 26 insertions(+), 34 deletions(-) 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 }); };