mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 01:27:36 +02:00
refactor icon handling to use webextension-polyfill for browser compatibility
This commit is contained in:
+4
-2
@@ -1,3 +1,5 @@
|
||||
import { browser } from 'webextension-polyfill-ts'
|
||||
|
||||
export async function updateIcon(countryCode: string | null) {
|
||||
let validCode
|
||||
if (countryCode === 'cloudflare') {
|
||||
@@ -57,12 +59,12 @@ export async function updateIcon(countryCode: string | null) {
|
||||
|
||||
try {
|
||||
const bitmap = await loadImageBitmap(validCode)
|
||||
chrome.action.setIcon({ imageData: await processImage(bitmap) })
|
||||
browser.action.setIcon({ imageData: await processImage(bitmap) })
|
||||
} catch (error) {
|
||||
console.error('Primary flag failed, trying unknown:', error)
|
||||
try {
|
||||
const unknownBitmap = await loadImageBitmap('unknown')
|
||||
chrome.action.setIcon({ imageData: await processImage(unknownBitmap) })
|
||||
browser.action.setIcon({ imageData: await processImage(unknownBitmap) })
|
||||
} catch (fallbackError) {
|
||||
console.error('Both flag assets failed:', fallbackError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user