diff --git a/app/ts/background/backgroundUtils.ts b/app/ts/background/backgroundUtils.ts index 55290565..79d07989 100644 --- a/app/ts/background/backgroundUtils.ts +++ b/app/ts/background/backgroundUtils.ts @@ -84,19 +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) { + 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 b49f7f50..b1afe295 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' @@ -15,7 +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 }) + 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) { 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 })