From 03e1508afca3a2b550b583ee26a5c718d7339d74 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:48:57 +0800 Subject: [PATCH] feat: support to save and load theme setting from localStorage (#342) --- src/layout/components/NavBar.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/layout/components/NavBar.vue b/src/layout/components/NavBar.vue index b7cc0f41..f7f253e0 100644 --- a/src/layout/components/NavBar.vue +++ b/src/layout/components/NavBar.vue @@ -90,6 +90,14 @@ limitations under the License. --> const pageTitle = ref(""); const theme = ref(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[]) {