feat: support to save and load theme setting from localStorage

This commit is contained in:
rick 2023-11-21 07:19:03 +00:00 committed by Zhao Xiaojie
parent 8618a9440e
commit 08ff16b3c3

View File

@ -90,6 +90,14 @@ limitations under the License. -->
const pageTitle = ref<string>("");
const theme = ref<boolean>(true);
const savedTheme = window.localStorage.getItem("theme-is-dark");
if (savedTheme === "false") {
theme.value = false;
} else if (savedTheme === "") {
// read the theme preference from system setting if there is no user setting
theme.value = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
}
changeTheme();
resetDuration();
getVersion();
@ -107,6 +115,7 @@ limitations under the License. -->
root.classList.remove(Themes.Dark);
appStore.setTheme(Themes.Light);
}
window.localStorage.setItem("theme-is-dark", String(theme.value));
}
function getName(list: any[]) {