move all badge logic into WebExtension code
This commit is contained in:
parent
3805f12e17
commit
d8fd47a353
3 changed files with 36 additions and 14 deletions
5
index.js
5
index.js
|
@ -8,8 +8,6 @@ const DEFAULT_TAB = "about:newtab";
|
||||||
const SHOW_MENU_TIMEOUT = 100;
|
const SHOW_MENU_TIMEOUT = 100;
|
||||||
const HIDE_MENU_TIMEOUT = 300;
|
const HIDE_MENU_TIMEOUT = 300;
|
||||||
|
|
||||||
const MAJOR_VERSIONS = ["2.2.1"];
|
|
||||||
|
|
||||||
const INCOMPATIBLE_ADDON_IDS = [
|
const INCOMPATIBLE_ADDON_IDS = [
|
||||||
"pulse@mozilla.com",
|
"pulse@mozilla.com",
|
||||||
"snoozetabs@mozilla.com",
|
"snoozetabs@mozilla.com",
|
||||||
|
@ -258,9 +256,6 @@ const ContainerService = {
|
||||||
|
|
||||||
webExtension.startup().then(api => {
|
webExtension.startup().then(api => {
|
||||||
api.browser.runtime.onMessage.addListener((message, sender, sendReply) => {
|
api.browser.runtime.onMessage.addListener((message, sender, sendReply) => {
|
||||||
if (message.method === "checkForMajorUpgrade") {
|
|
||||||
sendReply(reason === "upgrade" && MAJOR_VERSIONS.indexOf(self.version) > -1);
|
|
||||||
}
|
|
||||||
if ("method" in message && methods.indexOf(message.method) !== -1) {
|
if ("method" in message && methods.indexOf(message.method) !== -1) {
|
||||||
sendReply(this[message.method](message));
|
sendReply(this[message.method](message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const MAJOR_VERSIONS = ["2.3.0"];
|
||||||
|
|
||||||
const assignManager = {
|
const assignManager = {
|
||||||
CLOSEABLE_WINDOWS: new Set([
|
CLOSEABLE_WINDOWS: new Set([
|
||||||
"about:startpage",
|
"about:startpage",
|
||||||
|
@ -467,14 +469,26 @@ browser.runtime.sendMessage({
|
||||||
}
|
}
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
||||||
browser.runtime.sendMessage({method: "checkForMajorUpgrade"}).then(upgrading=> {
|
|
||||||
if (upgrading) {
|
|
||||||
browser.browserAction.setBadgeBackgroundColor({color: "rgba(0,217,0,255)"});
|
|
||||||
browser.browserAction.setBadgeText({text: "NEW"});
|
|
||||||
}
|
|
||||||
}).catch((e) => { throw e;});
|
|
||||||
|
|
||||||
function disableAddon(tabId) {
|
function disableAddon(tabId) {
|
||||||
browser.browserAction.disable(tabId);
|
browser.browserAction.disable(tabId);
|
||||||
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
|
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getExtensionInfo() {
|
||||||
|
const manifestPath = browser.extension.getURL("manifest.json");
|
||||||
|
const response = await fetch(manifestPath);
|
||||||
|
const extensionInfo = await response.json();
|
||||||
|
return extensionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function displayBrowserActionBadge() {
|
||||||
|
const extensionInfo = await 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"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayBrowserActionBadge();
|
||||||
|
|
|
@ -55,6 +55,13 @@ function escaped(strings, ...values) {
|
||||||
return result.join("");
|
return result.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getExtensionInfo() {
|
||||||
|
const manifestPath = browser.extension.getURL("manifest.json");
|
||||||
|
const response = await fetch(manifestPath);
|
||||||
|
const extensionInfo = await response.json();
|
||||||
|
return extensionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
// This object controls all the panels, identities and many other things.
|
// This object controls all the panels, identities and many other things.
|
||||||
const Logic = {
|
const Logic = {
|
||||||
_identities: [],
|
_identities: [],
|
||||||
|
@ -92,8 +99,14 @@ const Logic = {
|
||||||
},
|
},
|
||||||
|
|
||||||
clearBrowserActionBadge() {
|
clearBrowserActionBadge() {
|
||||||
browser.browserAction.setBadgeBackgroundColor({color: ""});
|
getExtensionInfo().then(extensionInfo=>{
|
||||||
browser.browserAction.setBadgeText({text: ""});
|
const storage = browser.storage.local.get({browserActionBadgesClicked: []}).then(storage=>{
|
||||||
|
browser.browserAction.setBadgeBackgroundColor({color: ""});
|
||||||
|
browser.browserAction.setBadgeText({text: ""});
|
||||||
|
storage.browserActionBadgesClicked.push(extensionInfo.version);
|
||||||
|
browser.storage.local.set({browserActionBadgesClicked: storage.browserActionBadgesClicked});
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshIdentities() {
|
refreshIdentities() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue