Skip to content

Commit

Permalink
Add advanced setting for extension reload on update
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#717

Related feedback:
- uBlockOrigin/uBlock-issues#717 (comment)

New advanced setting: `extensionUpdateForceReload`

Default value: `false`

If set to `true`, the extension will unconditionally reload
when an update is available; otherwise the extension will
reload only when being explicitly disabled then enabled, or
when the browser is restarted.
  • Loading branch information
gorhill committed Sep 11, 2019
1 parent 0c4eabb commit 93f438f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
8 changes: 0 additions & 8 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ vAPI.app = {
},
};

// https://github.com/uBlockOrigin/uBlock-issues/issues/717
// Prevent the extensions from being restarted mid-session.
browser.runtime.onUpdateAvailable.addListener(details => {
const toInt = vAPI.app.intFromVersion;
if ( toInt(details.version) > toInt(vAPI.app.version) ) { return; }
browser.runtime.reload();
});

/******************************************************************************/
/******************************************************************************/

Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const µBlock = (function() { // jshint ignore:line
debugScriptlets: false,
debugScriptletInjector: false,
disableWebAssembly: false,
extensionUpdateForceReload: false,
ignoreRedirectFilters: false,
ignoreScriptInjectFilters: false,
loggerPopupType: 'popup',
Expand Down
55 changes: 30 additions & 25 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

// Load all: executed once.

µBlock.restart = (function() {

/******************************************************************************/
{
// >>>>> start of local scope

const µb = µBlock;

/******************************************************************************/

vAPI.app.onShutdown = function() {
const µb = µBlock;
µb.staticFilteringReverseLookup.shutdown();
µb.assets.updateStop();
µb.staticNetFilteringEngine.reset();
Expand All @@ -52,7 +52,7 @@ vAPI.app.onShutdown = function() {
// - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation.

var onAllReady = function() {
const onAllReady = function() {
µb.webRequest.start();

// Ensure that the resources allocated for decompression purpose (likely
Expand Down Expand Up @@ -86,6 +86,18 @@ var onAllReady = function() {
µb.contextMenu.update(null);
µb.firstInstall = false;

// https://github.com/uBlockOrigin/uBlock-issues/issues/717
// Prevent the extensions from being restarted mid-session.
browser.runtime.onUpdateAvailable.addListener(details => {
const toInt = vAPI.app.intFromVersion;
if (
µBlock.hiddenSettings.extensionUpdateForceReload === true ||
toInt(details.version) <= toInt(vAPI.app.version)
) {
vAPI.app.restart();
}
});

log.info(`All ready ${Date.now()-vAPI.T0} ms after launch`);
};

Expand All @@ -96,8 +108,8 @@ var onAllReady = function() {
// in already opened web pages, to remove whatever nuisance could make it to
// the web pages before uBlock was ready.

let initializeTabs = function() {
let handleScriptResponse = function(tabId, results) {
const initializeTabs = function() {
const handleScriptResponse = function(tabId, results) {
if (
Array.isArray(results) === false ||
results.length === 0 ||
Expand All @@ -106,10 +118,10 @@ let initializeTabs = function() {
return;
}
// Inject dclarative content scripts programmatically.
let manifest = chrome.runtime.getManifest();
const manifest = chrome.runtime.getManifest();
if ( manifest instanceof Object === false ) { return; }
for ( let contentScript of manifest.content_scripts ) {
for ( let file of contentScript.js ) {
for ( const contentScript of manifest.content_scripts ) {
for ( const file of contentScript.js ) {
vAPI.tabs.injectScript(tabId, {
file: file,
allFrames: contentScript.all_frames,
Expand All @@ -118,8 +130,8 @@ let initializeTabs = function() {
}
}
};
let bindToTabs = function(tabs) {
for ( let tab of tabs ) {
const bindToTabs = function(tabs) {
for ( const tab of tabs ) {
µb.tabContextManager.commit(tab.id, tab.url);
µb.bindTabToPageStats(tab.id);
// https://github.com/chrisaljoudi/uBlock/issues/129
Expand Down Expand Up @@ -241,7 +253,7 @@ const onUserSettingsReady = function(fetched) {
// Housekeeping, as per system setting changes

const onSystemSettingsReady = function(fetched) {
var mustSaveSystemSettings = false;
let mustSaveSystemSettings = false;
if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
µb.assets.remove(/^compiled\//);
mustSaveSystemSettings = true;
Expand Down Expand Up @@ -367,17 +379,10 @@ const onAdminSettingsRestored = function() {

/******************************************************************************/

return function() {
// https://github.com/gorhill/uBlock/issues/531
µb.restoreAdminSettings().then(( ) => {
onAdminSettingsRestored();
});
};

/******************************************************************************/

})();

/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/531
µb.restoreAdminSettings().then(( ) => {
onAdminSettingsRestored();
});

µBlock.restart();
// <<<<< end of local scope
}

0 comments on commit 93f438f

Please sign in to comment.