mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-04-29 22:14:27 +02:00
🐛 Fix icon not updating
This commit is contained in:
parent
9ca143350c
commit
3d40644224
@ -1,16 +1,31 @@
|
|||||||
import browser from "webextension-polyfill";
|
import browser from "webextension-polyfill";
|
||||||
|
|
||||||
|
const ICON_GRAY_PATH = new URL("../../assets/icon-gray.png", import.meta.url);
|
||||||
|
const ICON_PATH = new URL("../../assets/icon.png", import.meta.url);
|
||||||
|
|
||||||
|
let activeTabId: number | undefined;
|
||||||
|
|
||||||
export default async function onActivated() {
|
export default async function onActivated() {
|
||||||
const icon = await getBrowserActionIcon();
|
await setBrowserActionIcon();
|
||||||
|
browser.tabs.onUpdated.removeListener(setBrowserActionIcon);
|
||||||
|
browser.tabs.onUpdated.addListener(setBrowserActionIcon, {
|
||||||
|
tabId: activeTabId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setBrowserActionIcon() {
|
||||||
|
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
||||||
|
const activeTab = tabs[0];
|
||||||
|
if (activeTab) {
|
||||||
|
activeTabId = activeTab.id;
|
||||||
|
}
|
||||||
|
const icon = await getBrowserActionIcon(activeTab);
|
||||||
browser.browserAction.setIcon(icon);
|
browser.browserAction.setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBrowserActionIcon(): Promise<browser.Action.SetIconDetailsType> {
|
async function getBrowserActionIcon(
|
||||||
const ICON_GRAY_PATH = new URL("../../assets/icon-gray.png", import.meta.url);
|
activeTab: browser.Tabs.Tab | undefined
|
||||||
const ICON_PATH = new URL("../../assets/icon.png", import.meta.url);
|
): Promise<browser.Action.SetIconDetailsType> {
|
||||||
|
|
||||||
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
|
||||||
const activeTab = tabs[0];
|
|
||||||
if (!activeTab || !activeTab.url) return { path: ICON_GRAY_PATH.href };
|
if (!activeTab || !activeTab.url) return { path: ICON_GRAY_PATH.href };
|
||||||
try {
|
try {
|
||||||
const url = new URL(activeTab.url);
|
const url = new URL(activeTab.url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user