Merge 65c58667b1
into 82e8643a4f
This commit is contained in:
commit
dcb2feace2
2 changed files with 31 additions and 22 deletions
|
@ -1,20 +1,37 @@
|
||||||
const MAJOR_VERSIONS = ["2.3.0", "2.4.0", "6.2.0", "8.0.0"];
|
const MAJOR_VERSIONS = ["2.3.0", "2.4.0", "6.2.0", "8.0.0"];
|
||||||
const badge = {
|
const badge = {
|
||||||
async init() {
|
async init() {
|
||||||
const currentWindow = await browser.windows.getCurrent();
|
this.displayBrowserActionBadge("showVersionIndicator");
|
||||||
this.displayBrowserActionBadge(currentWindow);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async displayBrowserActionBadge() {
|
disableAddon(tabId) {
|
||||||
const extensionInfo = await backgroundLogic.getExtensionInfo();
|
browser.browserAction.disable(tabId);
|
||||||
const storage = await browser.storage.local.get({ browserActionBadgesClicked: [] });
|
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
|
||||||
|
},
|
||||||
|
|
||||||
|
async displayBrowserActionBadge(action) {
|
||||||
|
const extensionInfo = await backgroundLogic.getExtensionInfo();
|
||||||
|
function changeBadgeColorText(color, text){
|
||||||
|
browser.browserAction.setBadgeBackgroundColor({color: color});
|
||||||
|
browser.browserAction.setBadgeText({text: text});
|
||||||
|
}
|
||||||
|
if(action==="showVersionIndicator") {
|
||||||
|
const ActionBadgesClickedStorage = await browser.storage.local.get({browserActionBadgesClicked: []});
|
||||||
if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
|
if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
|
||||||
storage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
|
ActionBadgesClickedStorage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
|
||||||
browser.browserAction.setBadgeBackgroundColor({ color: "rgba(0,217,0,255)" });
|
changeBadgeColorText("rgba(0,217,0,255)", "NEW");
|
||||||
browser.browserAction.setBadgeText({ text: "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();
|
badge.init();
|
||||||
|
|
|
@ -197,6 +197,9 @@ const messageHandler = {
|
||||||
}, {urls: ["<all_urls>"], types: ["main_frame"]});
|
}, {urls: ["<all_urls>"], types: ["main_frame"]});
|
||||||
|
|
||||||
browser.tabs.onCreated.addListener((tab) => {
|
browser.tabs.onCreated.addListener((tab) => {
|
||||||
|
if (tab.incognito) {
|
||||||
|
badge.disableAddon(tab.id);
|
||||||
|
}
|
||||||
// lets remember the last tab created so we can close it if it looks like a redirect
|
// lets remember the last tab created so we can close it if it looks like a redirect
|
||||||
this.lastCreatedTab = tab;
|
this.lastCreatedTab = tab;
|
||||||
if (tab.cookieStoreId) {
|
if (tab.cookieStoreId) {
|
||||||
|
@ -241,23 +244,12 @@ const messageHandler = {
|
||||||
|
|
||||||
// When the user opens their _ tab, give them the achievement
|
// When the user opens their _ tab, give them the achievement
|
||||||
if (countOfContainerTabsOpened === 100) {
|
if (countOfContainerTabsOpened === 100) {
|
||||||
const storage = await browser.storage.local.get({achievements: []});
|
badge.displayBrowserActionBadge("showAchievement");
|
||||||
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"});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async onFocusChangedCallback(windowId) {
|
async onFocusChangedCallback(windowId) {
|
||||||
assignManager.removeContextMenu();
|
assignManager.removeContextMenu();
|
||||||
// browserAction loses background color in new windows ...
|
|
||||||
// https://bugzil.la/1314674
|
|
||||||
// https://github.com/mozilla/testpilot-containers/issues/608
|
|
||||||
// ... so re-call displayBrowserActionBadge on window changes
|
|
||||||
badge.displayBrowserActionBadge();
|
|
||||||
browser.tabs.query({active: true, windowId}).then((tabs) => {
|
browser.tabs.query({active: true, windowId}).then((tabs) => {
|
||||||
if (tabs && tabs[0]) {
|
if (tabs && tabs[0]) {
|
||||||
assignManager.calculateContextMenu(tabs[0]);
|
assignManager.calculateContextMenu(tabs[0]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue