Skip to content

Commit

Permalink
feat(popup): Adds logic to dismiss badge when the popup closes
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Apr 2, 2024
1 parent 82050c6 commit 59d0df3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,14 @@ chrome.tabs.onUpdated.addListener(async function (tabId, details, tab) {
chrome.tabs.onActivated.addListener(function(activeInfo){
getTabById(activeInfo.tabId, updateToolbarButton);
});

chrome.runtime.onConnect.addListener(function (port) {
if (port.name === 'popup') {
port.onDisconnect.addListener(function () {
chrome.storage.local.get('options', function (items) {
items.options['dismiss_bagde'] = true;
saveOptionsAndUpdateToolbar(items.options);
});
});
}
});
5 changes: 5 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ function showHideReceiptsWarning (tabs){
save_options()
});
}

// Use the messaging APIs to set up a Port between the popup and background
// page. We should get a onDisconnect event in the background page when
// the popup goes away.
chrome.runtime.connect({ name: "popup" });
})();
2 changes: 1 addition & 1 deletion src/toolbar_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function updateToolbarButton(tab) {

chrome.storage.local.get('options', function(items){

if ('dismiss_class_action_info' in items['options']) {
if ('dismiss_bagde' in items['options'] && items['options']['dismiss_bagde']) {
chrome.browserAction.setBadgeText({});
} else {
chrome.browserAction.setBadgeText({ text: '🎁' });
Expand Down

0 comments on commit 59d0df3

Please sign in to comment.