74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
|
|
const themeManager = {
|
|
existingTheme: null,
|
|
init() {
|
|
this.check();
|
|
|
|
const port = browser.runtime.connect();
|
|
port.onMessage.addListener(m => {
|
|
if (m.type === "lightweight-theme-changed") {
|
|
this.update(m.theme);
|
|
}
|
|
});
|
|
},
|
|
setPopupIcon(theme) {
|
|
let icons = {
|
|
16: "img/container-site-d-24.png",
|
|
32: "img/container-site-d-48.png"
|
|
};
|
|
if (theme === "firefox-compact-dark@mozilla.org") {
|
|
icons = {
|
|
16: "img/container-site-w-24.png",
|
|
32: "img/container-site-w-48.png"
|
|
};
|
|
}
|
|
browser.browserAction.setIcon({
|
|
path: icons
|
|
});
|
|
},
|
|
check() {
|
|
browser.runtime.sendMessage({
|
|
method: "getTheme"
|
|
}).then((theme) => {
|
|
this.update(theme);
|
|
}).catch(() => {
|
|
throw new Error("Unable to get theme");
|
|
});
|
|
},
|
|
update(theme) {
|
|
if (this.existingTheme !== theme) {
|
|
this.setPopupIcon(theme);
|
|
this.existingTheme = theme;
|
|
}
|
|
}
|
|
};
|
|
|
|
themeManager.init();
|
|
|
|
browser.runtime.sendMessage({
|
|
method: "getPreference",
|
|
pref: "browser.privatebrowsing.autostart"
|
|
}).then(pbAutoStart => {
|
|
|
|
// We don't want to disable the addon if we are in auto private-browsing.
|
|
if (!pbAutoStart) {
|
|
browser.tabs.onCreated.addListener(tab => {
|
|
if (tab.incognito) {
|
|
disableAddon(tab.id);
|
|
}
|
|
});
|
|
|
|
browser.tabs.query({}).then(tabs => {
|
|
for (let tab of tabs) { // eslint-disable-line prefer-const
|
|
if (tab.incognito) {
|
|
disableAddon(tab.id);
|
|
}
|
|
}
|
|
}).catch(() => {});
|
|
}
|
|
}).catch(() => {});
|
|
|
|
function disableAddon(tabId) {
|
|
browser.browserAction.disable(tabId);
|
|
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
|
|
}
|