Skip to content
27 changes: 20 additions & 7 deletions src/js/background/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ const badge = {
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
},

async displayBrowserActionBadge() {
async displayBrowserActionBadge(action) {
const extensionInfo = await backgroundLogic.getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});

if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
storage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
browser.browserAction.setBadgeBackgroundColor({color: "rgba(0,217,0,255)"});
browser.browserAction.setBadgeText({text: "NEW"});
function changeBadgeColorText(color, text){
browser.browserAction.setBadgeBackgroundColor({color: color});
browser.browserAction.setBadgeText({text: text});
}
if(action==="remove"){
const ActionBadgesClickedStorage = await browser.storage.local.get({browserActionBadgesClicked: []});
if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
ActionBadgesClickedStorage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
changeBadgeColorText("rgba(0,217,0,255)", "NEW")
}
}
else if (action==="showAchievement"){
const achievementsStorage = await browser.storage.local.get({achievements: []});
achievementsStorage.achievements.push({"name": "manyContainersOpened", "done": false});
// use set and spread to create a unique array
const achievements = [...new Set(achievementsStorage.achievements)];
browser.storage.local.set({achievements});
changeBadgeColorText("rgba(0,217,0,255)", "NEW");
}
}

};

badge.init();
10 changes: 2 additions & 8 deletions src/js/background/messageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,7 @@ const messageHandler = {

// When the user opens their _ tab, give them the achievement
if (countOfContainerTabsOpened === 100) {
const storage = await browser.storage.local.get({achievements: []});
storage.achievements.push({"name": "manyContainersOpened", "done": false});
// use set and spread to create a unique array
const achievements = [...new Set(storage.achievements)];
browser.storage.local.set({achievements});
browser.browserAction.setBadgeBackgroundColor({color: "rgba(0,217,0,255)"});
browser.browserAction.setBadgeText({text: "NEW"});
badge.displayBrowserActionBadge("showAchievement");
}
},

Expand All @@ -187,7 +181,7 @@ const messageHandler = {
// https://bugzil.la/1314674
// https://github.com/mozilla/testpilot-containers/issues/608
// ... so re-call displayBrowserActionBadge on window changes
badge.displayBrowserActionBadge();
badge.displayBrowserActionBadge("remove");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action is actually "showVersionIndicator". We (ab)use it to get around https://bugzilla.mozilla.org/show_bug.cgi?id=1314674 but it looks like that bug is fixed now? So we can just remove this call now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groovecoder okay, so I should only focus on refactoring badge.displayBrowserActionBadge to handle

  1. when the user opens the 100th container and;
  2. line 5 in badge.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that sounds right. And line 5 in badge.js is the "showVersionIndicator" action.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, I have effected the changes

browser.tabs.query({active: true, windowId}).then((tabs) => {
if (tabs && tabs[0]) {
assignManager.calculateContextMenu(tabs[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Logic = {
async init() {
// Remove browserAction "upgraded" badge when opening panel
this.clearBrowserActionBadge();

// Retrieve the list of identities.
const identitiesPromise = this.refreshIdentities();

Expand Down Expand Up @@ -159,7 +159,7 @@ const Logic = {
});
},

async clearBrowserActionBadge() {
async clearBrowserActionBadge() {
const extensionInfo = await getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});
browser.browserAction.setBadgeBackgroundColor({color: null});
Expand Down