Skip to content

Commit

Permalink
Change the extension icon in a timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Dec 20, 2024
1 parent d2d4c18 commit 28e2c6e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 28e2c6e

Please sign in to comment.