From 9236845c24770165b6482642125a1b48502e1f4b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 9 Apr 2023 14:02:01 -0400 Subject: [PATCH] Add informative tooltip re. unprocessed requests at launch Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2585 --- platform/common/vapi-background.js | 18 ++++++++---------- src/_locales/en/messages.json | 4 ++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 004750e54..df61e2279 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -676,9 +676,8 @@ if ( webext.browserAction instanceof Object ) { { const browserAction = vAPI.browserAction; - const titleTemplate = - browser.runtime.getManifest().browser_action.default_title + - ' ({badge})'; + const titleTemplate = `${browser.runtime.getManifest().browser_action.default_title} ({badge})`; + const browserLaunchIssue = browser.i18n.getMessage('unprocessedRequestTooltip'); const icons = [ { path: { '16': 'img/icon_16-off.png', '32': 'img/icon_32-off.png' } }, { path: { '16': 'img/icon_16.png', '32': 'img/icon_32.png' } }, @@ -778,8 +777,9 @@ if ( webext.browserAction instanceof Object ) { const tab = await vAPI.tabs.get(tabId); if ( tab === null ) { return; } + const hasUnprocessedRequest = vAPI.net && vAPI.net.hasUnprocessedRequest(tabId); const { parts, state } = details; - const { badge, color } = vAPI.net && vAPI.net.hasUnprocessedRequest(tabId) + const { badge, color } = hasUnprocessedRequest ? { badge: '!', color: '#FC0' } : details; @@ -804,13 +804,11 @@ if ( webext.browserAction instanceof Object ) { // - the platform does not support browserAction.setIcon(); OR // - the rendering of the badge is disabled if ( browserAction.setTitle !== undefined ) { - browserAction.setTitle({ - tabId: tab.id, - title: titleTemplate.replace( - '{badge}', + const title = hasUnprocessedRequest && browserLaunchIssue || + titleTemplate.replace('{badge}', state === 1 ? (badge !== '' ? badge : '0') : 'off' - ) - }); + ); + browserAction.setTitle({ tabId: tab.id, title }); } if ( vAPI.contextMenu instanceof Object ) { diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index f2d6243fb..f135cd56d 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -1265,6 +1265,10 @@ "message": "Click to load", "description": "Message used in frame placeholders" }, + "unprocessedRequestTooltip": { + "message": "Could not filter properly at browser launch.\nReload the page to ensure proper filtering", + "description": "Tooltip for the toolbar icon. Use newline character(s) where appropriate to prevent tooltip from being too long horizontally" + }, "dummy": { "message": "This entry must be the last one", "description": "so we dont need to deal with comma for last entry"