From 28e2c6eec1714ceaa9be02a2ea8257e356d786b9 Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Fri, 20 Dec 2024 12:52:31 +0100 Subject: [PATCH] Change the extension icon in a timeout --- packages/extension/src/background.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/extension/src/background.ts b/packages/extension/src/background.ts index ea00e793..3d30c7ad 100644 --- a/packages/extension/src/background.ts +++ b/packages/extension/src/background.ts @@ -77,6 +77,26 @@ chrome.runtime.onConnect.addListener(port => { port.onDisconnect.addListener(() => on_disconnected(port)) }) +function toggle_action_icon(tab_id: Tab_Id) { + + if (script_content_map.get(tab_id)?.detection?.Solid) { + chrome.action.setIcon({tabId: tab_id, path: icons.blue}) + + /* + For some reason setting the icon immediately does not always work + */ + setTimeout(() => { + if (script_content_map.get(tab_id)?.detection?.Solid) { + chrome.action.setIcon({tabId: tab_id, path: icons.blue}) + } else { + chrome.action.setIcon({tabId: tab_id, path: icons.gray}) + } + }, 600) + } else { + chrome.action.setIcon({tabId: tab_id, path: icons.gray}) + } +} + function on_connected(port: bridge.Port) { DEV: {log('Port connected', port)} @@ -178,9 +198,7 @@ function on_disconnected(port: bridge.Port) { bridge.port_post_message(devtools.port, 'Versions', null) } - - // Change the popup icon back to gray - chrome.action.setIcon({tabId: tab_id, path: icons.gray}) + toggle_action_icon(tab_id) break } @@ -230,8 +248,7 @@ function on_message(port: bridge.Port, e: bridge.Message) { bridge.port_post_message_obj(popup.port, e) } - // Change the popup icon to indicate that Solid is present on the page - chrome.action.setIcon({tabId: tab_id, path: icons.blue}) + toggle_action_icon(tab_id) break }