Add ability to check for theme dark on changing themes. Fixes #207

This commit is contained in:
Jonathan Kingston
2017-02-22 17:02:53 +00:00
parent 29f3562c8b
commit f1c2cbc686
2 changed files with 98 additions and 0 deletions
+47
View File
@@ -1,3 +1,50 @@
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"