From 0c9576d3e609d3bc43ed5468ec4a8eb017642ad8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 7 Mar 2023 16:02:09 -0500 Subject: [PATCH] Show a distinct toolbar icon until filtering engines are fully initialized Related discussion: - https://github.com/uBlockOrigin/uAssets/discussions/16939 Until uBO's filtering engines are properly initialized, there will be a distinct toolbar icon to help users understand that uBO may not be fully initialized when a webpage is loaded -- often the cause of improper filtering of trackers/ads at browser launch. --- platform/common/vapi-background.js | 10 ++++++++++ src/img/icon_16-loading.png | Bin 0 -> 570 bytes src/img/icon_32-loading.png | Bin 0 -> 1089 bytes src/js/start.js | 28 +++++++++++++++++----------- src/js/tab.js | 1 + 5 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 src/img/icon_16-loading.png create mode 100644 src/img/icon_32-loading.png diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index fd1820232..071fe9caf 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -808,6 +808,16 @@ if ( webext.browserAction instanceof Object ) { vAPI.contextMenu.onMustUpdate(tabId); } }; + + vAPI.setDefaultIcon = function(flavor) { + if ( browserAction.setIcon === undefined ) { return; } + browserAction.setIcon({ + path: { + '16': `img/icon_16${flavor}.png`, + '32': `img/icon_32${flavor}.png`, + } + }); + }; } browser.browserAction.onClicked.addListener(function(tab) { diff --git a/src/img/icon_16-loading.png b/src/img/icon_16-loading.png new file mode 100644 index 0000000000000000000000000000000000000000..54d274e22ecace0df0f32ae4ca83a55e87302d0a GIT binary patch literal 570 zcmV-A0>%A_P)NW$24aMIsV3z>OaO!toZlODXa|v+E zjeEjB|2wO2*MgomV02W*Z~<2V0zMCLRcEX4@fQ3_LB~P`K)HaZQYNi>gp)Za<{>u= zjYD2tG#8)*P`)4KM&T566ZAF^2U?$k3PEcU^6MTz`EwpX3#7}9!)MU<8Tvj!_Bn(f zKr9QPIHVs}L9LBfrOjU7&5S3YcXtfCK?-$pbX2mc< z3?sydPZg7$gJSxt)=J|^WoKaKhal5u-(vb=2kC2mQy<$CVOⓈM(~q&Mh~}37Z$7 z01p6=_|k>qc92W@$o$gG+{7CGjkJ*&-H1BwC`)YpgDI@*E@NrFN?qVLtgR6gcZ^&z zg{OTQ5I_jf@&W?f*fvgj)CiJG%=^^>5-1+y)wWI${B|ucVVUm|WW$17T&fXc5d`Go z#%ner01ZGkJfvDJ_s)f0uC zE7kAZ2Eid%pVBRO5j;DV=9eX{Sb&OT%T~S;Ab3F+A=`CxZim2G@V{Srj%1$$W(x(R zksWGP0z?*WcEgBQw?Eznp+fU};Mi(DM{%e?x==s{#W7cvfLjOQuaEVME0=)3KY?(M z9@>A%e2(nMQj`G=$x>YgrjD2Hvu!Y+BPl9H7ZIRTCtyjGI#>pmAwaQ4O?~rMsJznX zldVSE_uAq)jc@4B^sqUN`w { staticFilteringReverseLookup.shutdown(); io.updateStop(); staticNetFilteringEngine.reset(); @@ -90,7 +94,7 @@ vAPI.app.onShutdown = function() { // https://bugzilla.mozilla.org/show_bug.cgi?id=1652925#c19 // Mind discarded tabs. -const initializeTabs = async function() { +const initializeTabs = async ( ) => { const manifest = browser.runtime.getManifest(); if ( manifest instanceof Object === false ) { return; } @@ -140,7 +144,7 @@ const initializeTabs = async function() { // https://www.reddit.com/r/uBlockOrigin/comments/s7c9go/ // Abort suspending network requests when uBO is merely being installed. -const onVersionReady = function(lastVersion) { +const onVersionReady = lastVersion => { if ( lastVersion === vAPI.app.version ) { return; } vAPI.storage.set({ version: vAPI.app.version }); @@ -179,7 +183,7 @@ const onVersionReady = function(lastVersion) { // https://github.com/uBlockOrigin/uBlock-issues/issues/1433 // Allow admins to add their own trusted-site directives. -const onNetWhitelistReady = function(netWhitelistRaw, adminExtra) { +const onNetWhitelistReady = (netWhitelistRaw, adminExtra) => { if ( typeof netWhitelistRaw === 'string' ) { netWhitelistRaw = netWhitelistRaw.split('\n'); } @@ -201,7 +205,7 @@ const onNetWhitelistReady = function(netWhitelistRaw, adminExtra) { // User settings are in memory -const onUserSettingsReady = function(fetched) { +const onUserSettingsReady = fetched => { // Terminate suspended state? const tnow = Date.now() - vAPI.T0; if ( @@ -271,7 +275,7 @@ const onUserSettingsReady = function(fetched) { // https://github.com/uBlockOrigin/uBlock-issues/issues/1365 // Wait for removal of invalid cached data to be completed. -const onCacheSettingsReady = async function(fetched) { +const onCacheSettingsReady = async fetched => { if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) { µb.compiledFormatChanged = true; µb.selfieIsInvalid = true; @@ -289,7 +293,7 @@ const onCacheSettingsReady = async function(fetched) { /******************************************************************************/ -const onHiddenSettingsReady = async function() { +const onHiddenSettingsReady = async ( ) => { // Maybe customize webext flavor if ( µb.hiddenSettings.modifyWebextFlavor !== 'unset' ) { const tokens = µb.hiddenSettings.modifyWebextFlavor.split(/\s+/); @@ -333,7 +337,7 @@ const onHiddenSettingsReady = async function() { /******************************************************************************/ -const onFirstFetchReady = function(fetched, adminExtra) { +const onFirstFetchReady = (fetched, adminExtra) => { // https://github.com/uBlockOrigin/uBlock-issues/issues/507 // Firefox-specific: somehow `fetched` is undefined under certain // circumstances even though we asked to load with default values. @@ -358,14 +362,14 @@ const onFirstFetchReady = function(fetched, adminExtra) { /******************************************************************************/ -const toFetch = function(from, fetched) { +const toFetch = (from, fetched) => { for ( const k in from ) { if ( from.hasOwnProperty(k) === false ) { continue; } fetched[k] = from[k]; } }; -const fromFetch = function(to, fetched) { +const fromFetch = (to, fetched) => { for ( const k in to ) { if ( to.hasOwnProperty(k) === false ) { continue; } if ( fetched.hasOwnProperty(k) === false ) { continue; } @@ -373,7 +377,7 @@ const fromFetch = function(to, fetched) { } }; -const createDefaultProps = function() { +const createDefaultProps = ( ) => { const fetchableProps = { 'dynamicFilteringString': µb.dynamicFilteringDefault.join('\n'), 'urlFilteringString': '', @@ -469,6 +473,8 @@ if ( selfieIsValid !== true ) { // This can be used to defer filtering decision-making. µb.readyToFilter = true; +vAPI.setDefaultIcon(''); + // Start network observers. webRequest.start(); diff --git a/src/js/tab.js b/src/js/tab.js index 2e38931a1..e13e0a00b 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -1119,6 +1119,7 @@ vAPI.tabs = new vAPI.Tabs(); // bit 3 = hide badge µb.updateToolbarIcon = function(tabId, newParts = 0b0111) { + if ( this.readyToFilter === false ) { return; } if ( typeof tabId !== 'number' ) { return; } if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; } const currentParts = tabIdToDetails.get(tabId);