From 2ae6707982ca79e0615038f22d37721e94c984ea Mon Sep 17 00:00:00 2001 From: GrzegorzZajac000 Date: Thu, 3 Oct 2024 13:09:40 +0200 Subject: [PATCH] #1663 setIcon FIX --- src/background/background.js | 4 +++- src/background/functions/setIcon.js | 11 ++++++++--- src/optionsPage/functions/setIconSelect.js | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/background/background.js b/src/background/background.js index 33d2800..cd5e0bf 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -18,7 +18,7 @@ // const browser = require('webextension-polyfill'); -const { onConnect, onCommand, onContextMenuClick, onInstalled, getBrowserInfo, onMessage, onStartup, browserAction, createContextMenus, dummyGetLocalStorage } = require('./functions'); +const { onConnect, onCommand, onContextMenuClick, onInstalled, getBrowserInfo, onMessage, onStartup, browserAction, createContextMenus, dummyGetLocalStorage, setIcon } = require('./functions'); const { onTabRemoved, onTabUpdated, onTabActivated } = require('./tabs'); const browserInfo = getBrowserInfo(); @@ -47,3 +47,5 @@ browser.tabs.onActivated.addListener(onTabActivated); setInterval(() => { return dummyGetLocalStorage(); }, 25 * 1000); + +setIcon(null, false, false); diff --git a/src/background/functions/setIcon.js b/src/background/functions/setIcon.js index 6390ea1..5a31e4c 100644 --- a/src/background/functions/setIcon.js +++ b/src/background/functions/setIcon.js @@ -49,16 +49,21 @@ const getIconObj = async (tabID, isActive) => { iconFileName = isActive ? typeFilename : `${typeFilename}gray`; } - return { + const iconObj = { path: { 16: browser.runtime.getURL(`images/icons/icon16${iconFileName}.png`), 32: browser.runtime.getURL(`images/icons/icon32${iconFileName}.png`), 48: browser.runtime.getURL(`images/icons/icon48${iconFileName}.png`), 96: browser.runtime.getURL(`images/icons/icon96${iconFileName}.png`), 128: browser.runtime.getURL(`images/icons/icon128${iconFileName}.png`) - }, - tabId: tabID + } }; + + if (tabID) { + iconObj.tabId = tabID; + } + + return iconObj; }; const setIcon = async (tabID, isActive = true, changeTitle = false) => { diff --git a/src/optionsPage/functions/setIconSelect.js b/src/optionsPage/functions/setIconSelect.js index 4594476..ae9a98f 100644 --- a/src/optionsPage/functions/setIconSelect.js +++ b/src/optionsPage/functions/setIconSelect.js @@ -20,7 +20,7 @@ const SlimSelect = require('slim-select'); const browser = require('webextension-polyfill'); const { loadFromLocalStorage, saveToLocalStorage } = require('../../localStorage'); -const checkTabCS = require('../../background/functions/checkTabCS'); +const setIcon = require('../../background/functions/setIcon'); const setIconSelect = async () => { const { extIcon } = await loadFromLocalStorage(['extIcon']); @@ -57,7 +57,8 @@ const setIconSelect = async () => { const tabID = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0].id); await saveToLocalStorage({ extIcon: parseInt(item[0].value, 10) }); - await checkTabCS(tabID); + await setIcon(null, false, false); + await setIcon(tabID, false, false); } } });