Skip to content

Commit

Permalink
Merge branch 'main' into access-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KillariDev authored Dec 10, 2024
2 parents a396897 + 6b82d5c commit 7c7bd9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
29 changes: 17 additions & 12 deletions app/ts/background/backgroundUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>))(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<void>))(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) {
Expand Down
10 changes: 8 additions & 2 deletions app/ts/background/iconHandler.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions app/ts/background/websiteAccessSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof x> => x !== undefined)
.reduce(selectLongerMatch, { length: 0, location: Infinity })

Expand Down

0 comments on commit 7c7bd9d

Please sign in to comment.