2525
2626// Load all: executed once.
2727
28- µBlock.restart = (function() {
29-
30- /******************************************************************************/
28+ {
29+ // >>>>> start of local scope
3130
3231const µb = µBlock;
3332
3433/******************************************************************************/
3534
3635vAPI.app.onShutdown = function() {
36+ const µb = µBlock;
3737 µb.staticFilteringReverseLookup.shutdown();
3838 µb.assets.updateStop();
3939 µb.staticNetFilteringEngine.reset();
@@ -52,7 +52,7 @@ vAPI.app.onShutdown = function() {
5252// - Initialize internal state with maybe already existing tabs.
5353// - Schedule next update operation.
5454
55- var onAllReady = function() {
55+ const onAllReady = function() {
5656 µb.webRequest.start();
5757
5858 // Ensure that the resources allocated for decompression purpose (likely
@@ -86,6 +86,18 @@ var onAllReady = function() {
8686 µb.contextMenu.update(null);
8787 µb.firstInstall = false;
8888
89+ // https://github.com/uBlockOrigin/uBlock-issues/issues/717
90+ // Prevent the extensions from being restarted mid-session.
91+ browser.runtime.onUpdateAvailable.addListener(details => {
92+ const toInt = vAPI.app.intFromVersion;
93+ if (
94+ µBlock.hiddenSettings.extensionUpdateForceReload === true ||
95+ toInt(details.version) <= toInt(vAPI.app.version)
96+ ) {
97+ vAPI.app.restart();
98+ }
99+ });
100+
89101 log.info(`All ready ${Date.now()-vAPI.T0} ms after launch`);
90102};
91103
@@ -96,8 +108,8 @@ var onAllReady = function() {
96108// in already opened web pages, to remove whatever nuisance could make it to
97109// the web pages before uBlock was ready.
98110
99- let initializeTabs = function() {
100- let handleScriptResponse = function(tabId, results) {
111+ const initializeTabs = function() {
112+ const handleScriptResponse = function(tabId, results) {
101113 if (
102114 Array.isArray(results) === false ||
103115 results.length === 0 ||
@@ -106,10 +118,10 @@ let initializeTabs = function() {
106118 return;
107119 }
108120 // Inject dclarative content scripts programmatically.
109- let manifest = chrome.runtime.getManifest();
121+ const manifest = chrome.runtime.getManifest();
110122 if ( manifest instanceof Object === false ) { return; }
111- for ( let contentScript of manifest.content_scripts ) {
112- for ( let file of contentScript.js ) {
123+ for ( const contentScript of manifest.content_scripts ) {
124+ for ( const file of contentScript.js ) {
113125 vAPI.tabs.injectScript(tabId, {
114126 file: file,
115127 allFrames: contentScript.all_frames,
@@ -118,8 +130,8 @@ let initializeTabs = function() {
118130 }
119131 }
120132 };
121- let bindToTabs = function(tabs) {
122- for ( let tab of tabs ) {
133+ const bindToTabs = function(tabs) {
134+ for ( const tab of tabs ) {
123135 µb.tabContextManager.commit(tab.id, tab.url);
124136 µb.bindTabToPageStats(tab.id);
125137 // https://github.com/chrisaljoudi/uBlock/issues/129
@@ -241,7 +253,7 @@ const onUserSettingsReady = function(fetched) {
241253// Housekeeping, as per system setting changes
242254
243255const onSystemSettingsReady = function(fetched) {
244- var mustSaveSystemSettings = false;
256+ let mustSaveSystemSettings = false;
245257 if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
246258 µb.assets.remove(/^compiled\//);
247259 mustSaveSystemSettings = true;
@@ -367,17 +379,10 @@ const onAdminSettingsRestored = function() {
367379
368380/******************************************************************************/
369381
370- return function() {
371- // https://github.com/gorhill/uBlock/issues/531
372- µb.restoreAdminSettings().then(( ) => {
373- onAdminSettingsRestored();
374- });
375- };
376-
377- /******************************************************************************/
378-
379- })();
380-
381- /******************************************************************************/
382+ // https://github.com/gorhill/uBlock/issues/531
383+ µb.restoreAdminSettings().then(( ) => {
384+ onAdminSettingsRestored();
385+ });
382386
383- µBlock.restart();
387+ // <<<<< end of local scope
388+ }
0 commit comments