mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 09:37:37 +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) {
|
export async function updateIcon(countryCode: string | null) {
|
||||||
let validCode
|
let validCode
|
||||||
if (countryCode === 'cloudflare') {
|
if (countryCode === 'cloudflare') {
|
||||||
@@ -57,12 +59,12 @@ export async function updateIcon(countryCode: string | null) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const bitmap = await loadImageBitmap(validCode)
|
const bitmap = await loadImageBitmap(validCode)
|
||||||
chrome.action.setIcon({ imageData: await processImage(bitmap) })
|
browser.action.setIcon({ imageData: await processImage(bitmap) })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Primary flag failed, trying unknown:', error)
|
console.error('Primary flag failed, trying unknown:', error)
|
||||||
try {
|
try {
|
||||||
const unknownBitmap = await loadImageBitmap('unknown')
|
const unknownBitmap = await loadImageBitmap('unknown')
|
||||||
chrome.action.setIcon({ imageData: await processImage(unknownBitmap) })
|
browser.action.setIcon({ imageData: await processImage(unknownBitmap) })
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
console.error('Both flag assets failed:', fallbackError)
|
console.error('Both flag assets failed:', fallbackError)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user