From 05a3b9ba50a1a1c748a397e5f03664d742b44b24 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Mon, 9 Dec 2024 14:15:00 +0200 Subject: [PATCH 1/4] update interceptors extension tooltip with the icon reason --- app/ts/background/backgroundUtils.ts | 15 +++++++++++++++ app/ts/background/iconHandler.ts | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/ts/background/backgroundUtils.ts b/app/ts/background/backgroundUtils.ts index 55290565..3ac0a64f 100644 --- a/app/ts/background/backgroundUtils.ts +++ b/app/ts/background/backgroundUtils.ts @@ -99,6 +99,21 @@ export async function setExtensionIcon(details: browser.action._SetIconDetails) } } +export async function setExtensionTitle(details: browser.action._SetTitleDetails) { + try { + const manifest = browser.runtime.getManifest() + if (manifest.manifest_version === 2) { + await browser.browserAction.setTitle(details) + } else { + await browser.action.setTitle(details) + } + checkAndThrowRuntimeLastError() + } catch { + console.warn('failed to set extension title') + console.warn(details) + } +} + export async function setExtensionBadgeText(details: browser.browserAction._SetBadgeTextDetails) { try { const manifest = browser.runtime.getManifest() diff --git a/app/ts/background/iconHandler.ts b/app/ts/background/iconHandler.ts index b49f7f50..98ab7689 100644 --- a/app/ts/background/iconHandler.ts +++ b/app/ts/background/iconHandler.ts @@ -1,7 +1,7 @@ import { getPrettySignerName } from '../components/subcomponents/signers.js' import { ICON_ACCESS_DENIED, ICON_INTERCEPTOR_DISABLED, ICON_NOT_ACTIVE, ICON_SIGNING, ICON_SIGNING_NOT_SUPPORTED, ICON_SIMULATING, PRIMARY_COLOR, TIME_BETWEEN_BLOCKS, WARNING_COLOR } from '../utils/constants.js' import { areWeBlocking, hasAccess, hasAddressAccess } from './accessManagement.js' -import { getActiveAddress, sendPopupMessageToOpenWindows, setExtensionBadgeBackgroundColor, setExtensionBadgeText, setExtensionIcon } from './backgroundUtils.js' +import { getActiveAddress, sendPopupMessageToOpenWindows, setExtensionBadgeBackgroundColor, setExtensionBadgeText, setExtensionIcon, setExtensionTitle } from './backgroundUtils.js' import { imageToUri } from '../utils/imageToUri.js' import { Future } from '../utils/future.js' import { RpcConnectionStatus, TabIcon, TabState, WebsiteTabConnections } from '../types/user-interface-types.js' @@ -16,6 +16,7 @@ async function setInterceptorIcon(tabId: number, icon: TabIcon, iconReason: stri await updateTabState(tabId, (previousState: TabState) => modifyObject(previousState, { tabIconDetails })) if (await getLastKnownCurrentTabId() === tabId) await sendPopupMessageToOpenWindows({ method: 'popup_websiteIconChanged', data: tabIconDetails }) await setExtensionIcon({ path: { 128: icon }, tabId }) + await setExtensionTitle({ title: iconReason }) } export async function updateExtensionIcon(websiteTabConnections: WebsiteTabConnections, tabId: number, websiteOrigin: string) { From f034e90e7503ebedc4a9f1234d537358a3cff218 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Mon, 9 Dec 2024 14:15:40 +0200 Subject: [PATCH 2/4] add tabid too --- app/ts/background/iconHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ts/background/iconHandler.ts b/app/ts/background/iconHandler.ts index 98ab7689..d4fb2c0b 100644 --- a/app/ts/background/iconHandler.ts +++ b/app/ts/background/iconHandler.ts @@ -16,7 +16,7 @@ async function setInterceptorIcon(tabId: number, icon: TabIcon, iconReason: stri await updateTabState(tabId, (previousState: TabState) => modifyObject(previousState, { tabIconDetails })) if (await getLastKnownCurrentTabId() === tabId) await sendPopupMessageToOpenWindows({ method: 'popup_websiteIconChanged', data: tabIconDetails }) await setExtensionIcon({ path: { 128: icon }, tabId }) - await setExtensionTitle({ title: iconReason }) + await setExtensionTitle({ title: iconReason, tabId }) } export async function updateExtensionIcon(websiteTabConnections: WebsiteTabConnections, tabId: number, websiteOrigin: string) { From 6f90d24fcc464407399e5efde10f71f3cd0cb078 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Mon, 9 Dec 2024 15:37:30 +0200 Subject: [PATCH 3/4] fix website access search type error --- app/ts/background/websiteAccessSearch.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/ts/background/websiteAccessSearch.ts b/app/ts/background/websiteAccessSearch.ts index cffdc6a4..2a919998 100644 --- a/app/ts/background/websiteAccessSearch.ts +++ b/app/ts/background/websiteAccessSearch.ts @@ -44,9 +44,7 @@ function calculateWebsiteAccessScore(entry: WebsiteAccess, query: string): Searc const titleMatch = entry.website.title ? computeSearchMatch(query, entry.website.title.toLowerCase()) : undefined const addressMatches = entry.addressAccess?.map((addr: WebsiteAddressAccess) => computeSearchMatch(query, addressString(addr.address).toLowerCase())) || [] - const bestAddressMatch = addressMatches.length > 0 ? addressMatches.reduce(selectLongerMatch) : undefined - - const bestResult = [urlMatch, titleMatch, bestAddressMatch] + const bestResult = [urlMatch, titleMatch, ...addressMatches] .filter((x): x is NonNullable => x !== undefined) .reduce(selectLongerMatch, { length: 0, location: Infinity }) From c8a4e75c6a9f8f23794940bb99758142147b1f1e Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 10 Dec 2024 11:36:09 +0200 Subject: [PATCH 4/4] move error handling farer away --- app/ts/background/backgroundUtils.ts | 36 ++++++++++------------------ app/ts/background/iconHandler.ts | 9 +++++-- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/ts/background/backgroundUtils.ts b/app/ts/background/backgroundUtils.ts index 3ac0a64f..79d07989 100644 --- a/app/ts/background/backgroundUtils.ts +++ b/app/ts/background/backgroundUtils.ts @@ -84,34 +84,24 @@ export function getHtmlFile(file: HTMLFile) { } export async function setExtensionIcon(details: browser.action._SetIconDetails) { - try { - const manifest = browser.runtime.getManifest() - if (manifest.manifest_version === 2) { - await browser.browserAction.setIcon(details) - } else { - // see https://issues.chromium.org/issues/337214677 - await (browser.action.setIcon as unknown as ((details: browser.action._SetIconDetails, callback: () => void) => Promise))(details, () => { browser.runtime.lastError }) - } - checkAndThrowRuntimeLastError() - } catch { - console.warn('failed to set extension icon') - console.warn(details) + const manifest = browser.runtime.getManifest() + if (manifest.manifest_version === 2) { + await browser.browserAction.setIcon(details) + } else { + // see https://issues.chromium.org/issues/337214677 + await (browser.action.setIcon as unknown as ((details: browser.action._SetIconDetails, callback: () => void) => Promise))(details, () => { browser.runtime.lastError }) } + checkAndThrowRuntimeLastError() } export async function setExtensionTitle(details: browser.action._SetTitleDetails) { - try { - const manifest = browser.runtime.getManifest() - if (manifest.manifest_version === 2) { - await browser.browserAction.setTitle(details) - } else { - await browser.action.setTitle(details) - } - checkAndThrowRuntimeLastError() - } catch { - console.warn('failed to set extension title') - console.warn(details) + const manifest = browser.runtime.getManifest() + if (manifest.manifest_version === 2) { + await browser.browserAction.setTitle(details) + } else { + await browser.action.setTitle(details) } + checkAndThrowRuntimeLastError() } export async function setExtensionBadgeText(details: browser.browserAction._SetBadgeTextDetails) { diff --git a/app/ts/background/iconHandler.ts b/app/ts/background/iconHandler.ts index d4fb2c0b..b1afe295 100644 --- a/app/ts/background/iconHandler.ts +++ b/app/ts/background/iconHandler.ts @@ -15,8 +15,13 @@ async function setInterceptorIcon(tabId: number, icon: TabIcon, iconReason: stri const tabIconDetails = { icon, iconReason } await updateTabState(tabId, (previousState: TabState) => modifyObject(previousState, { tabIconDetails })) if (await getLastKnownCurrentTabId() === tabId) await sendPopupMessageToOpenWindows({ method: 'popup_websiteIconChanged', data: tabIconDetails }) - await setExtensionIcon({ path: { 128: icon }, tabId }) - await setExtensionTitle({ title: iconReason, tabId }) + try { + await setExtensionIcon({ path: { 128: icon }, tabId }) + await setExtensionTitle({ title: iconReason, tabId }) + } catch (error) { + console.warn('failed to set interceptor icon and reason') + console.warn(error) + } } export async function updateExtensionIcon(websiteTabConnections: WebsiteTabConnections, tabId: number, websiteOrigin: string) {