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
This commit is contained in:
Raymond Hill 2019-09-06 13:03:06 -04:00
parent c55288281c
commit c8c2e11d09
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 26 additions and 34 deletions

View file

@ -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();
});
/******************************************************************************/

View file

@ -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 });
};