feat(browser-extension): add SET_BADGE handler to the background script and reset action badge text when disabling icon

This commit is contained in:
wanhose 2024-02-27 19:43:22 +01:00
parent c740b45e67
commit ca57b55514

View File

@ -107,6 +107,7 @@ chrome.runtime.onMessage.addListener((message, sender, callback) => {
case 'DISABLE_ICON':
if (isPage && tabId) {
chrome.action.setIcon({ path: '/assets/icons/disabled.png', tabId }, suppressLastError);
chrome.action.setBadgeText({ tabId, text: '' });
}
break;
case 'ENABLE_ICON':
@ -158,6 +159,12 @@ chrome.runtime.onMessage.addListener((message, sender, callback) => {
report(message, sender.tab);
}
break;
case 'SET_BADGE':
if (tabId) {
chrome.action.setBadgeBackgroundColor({ color: '#6b7280' });
chrome.action.setBadgeText({ tabId, text: message.value });
}
break;
case 'SET_HOSTNAME_STATE':
if (hostname && message.state.enabled === false) {
storage.set({ [hostname]: message.state });