Fixed confusing theme application until a choice is made.

This commit is contained in:
hackademix 2022-03-23 00:53:21 +01:00
parent f554d90199
commit 8848719881
2 changed files with 6 additions and 4 deletions

View File

@ -75,13 +75,14 @@
}
let refreshVintage = isVintage => {
document.documentElement.classList.toggle("vintage", isVintage);
document.documentElement.classList.toggle("vintage", isVintage === true);
if (browser.browserAction) {
browser.browserAction.setIcon({path: {64: `/img${isVintage ? "/vintage/" : "/"}ui-maybe64.png` }});
}
updateFavIcon(isVintage);
}
const THEMES = ["dark", "light", "auto"];
var Themes = {
setup(theme = null) {
if (theme) {
@ -94,6 +95,7 @@
} else {
if (localStorage) {
theme = localStorage.getItem("theme");
if (!THEMES.includes(theme)) theme = null;
}
if (!theme && browser && browser.storage) {
if (document.readyState === "loading") {
@ -102,8 +104,8 @@
return browser.storage.local.get(["theme"]).then(({theme}) => {
update(theme);
document.documentElement.style.visibility = "";
if (localStorage) localStorage.setItem("theme", theme)
return theme;
if (localStorage && theme) localStorage.setItem("theme", theme)
return theme || "auto";
});
}
}

View File

@ -147,7 +147,7 @@ document.querySelector("#version").textContent = _("Version",
UI.wireChoice("theme", o => Themes.setup(o && o.value) );
opt("vintageTheme", o => o ? Themes.setVintage(o.checked) : Themes.isVintage());
opt("vintageTheme", async o => await (o ? Themes.setVintage(o.checked) : Themes.isVintage()));
// PRESET CUSTOMIZER
{