diff --git a/gui/src/App.vue b/gui/src/App.vue index e9de2884..355c1acc 100644 --- a/gui/src/App.vue +++ b/gui/src/App.vue @@ -59,7 +59,7 @@ {{ themeSwitchLabel }} @@ -141,7 +141,8 @@ export default { outbounds: ["proxy"], outboundDropdownHover: {}, updateOutboundDropdown: true, - isDarkTheme: false, + themePreference: 'auto', + systemDark: window.matchMedia('(prefers-color-scheme: dark)').matches, }; }, computed: { @@ -161,10 +162,15 @@ export default { const lang = this.langs.find(l => l.flag === currentLang); return lang ? lang.code : "zh_CN"; }, + isDarkTheme() { + if (this.themePreference === 'dark') return true; + if (this.themePreference === 'light') return false; + return this.systemDark; + }, themeSwitchLabel() { - return this.isDarkTheme - ? this.$t("common.lightTheme") - : this.$t("common.darkTheme"); + if (this.themePreference === 'auto') return this.$t('common.autoTheme'); + if (this.themePreference === 'dark') return this.$t('common.darkTheme'); + return this.$t('common.lightTheme'); }, }, mounted() { @@ -236,6 +242,9 @@ export default { if (this.ws) { this.ws.close(); } + if (this._darkMediaQuery && this._onSystemThemeChange) { + this._darkMediaQuery.removeEventListener('change', this._onSystemThemeChange); + } }, methods: { connectWsMessage() { @@ -531,15 +540,24 @@ export default { this.$remount(); }, initTheme() { - this.isDarkTheme = localStorage.getItem("theme") === "dark"; + const stored = localStorage.getItem('theme'); + this.themePreference = (stored === 'dark' || stored === 'light') ? stored : 'auto'; + this._darkMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); + this._onSystemThemeChange = (e) => { + this.systemDark = e.matches; + this.applyThemeClass(); + }; + this._darkMediaQuery.addEventListener('change', this._onSystemThemeChange); this.applyThemeClass(); }, applyThemeClass() { - document.body.classList.toggle("theme-dark", this.isDarkTheme); + document.body.classList.toggle('theme-dark', this.isDarkTheme); }, toggleTheme() { - this.isDarkTheme = !this.isDarkTheme; - localStorage.setItem("theme", this.isDarkTheme ? "dark" : "light"); + const order = ['auto', 'light', 'dark']; + const idx = order.indexOf(this.themePreference); + this.themePreference = order[(idx + 1) % order.length]; + localStorage.setItem('theme', this.themePreference); this.applyThemeClass(); }, handleClickLogs() { diff --git a/gui/src/locales/en.js b/gui/src/locales/en.js index 78d876d2..b89114f7 100644 --- a/gui/src/locales/en.js +++ b/gui/src/locales/en.js @@ -20,6 +20,7 @@ export default { log: "Logs", darkTheme: "Dark Theme", lightTheme: "Light Theme", + autoTheme: "Auto Theme", }, welcome: { title: "Welcome", diff --git a/gui/src/locales/fa-ir.js b/gui/src/locales/fa-ir.js index 37d9162e..0b902d96 100644 --- a/gui/src/locales/fa-ir.js +++ b/gui/src/locales/fa-ir.js @@ -20,6 +20,7 @@ export default { log: "گزارش ها", darkTheme: "تم تیره", lightTheme: "تم روشن", + autoTheme: "تم خودکار", }, welcome: { title: "خوش آمدی", diff --git a/gui/src/locales/pt-br.js b/gui/src/locales/pt-br.js index d1afddd7..ddc2c2a5 100644 --- a/gui/src/locales/pt-br.js +++ b/gui/src/locales/pt-br.js @@ -20,6 +20,7 @@ export default { log: "Logs", darkTheme: "Tema Escuro", lightTheme: "Tema Claro", + autoTheme: "Tema Automático", }, welcome: { title: "Bem-vindo", diff --git a/gui/src/locales/ru.js b/gui/src/locales/ru.js index 7cf10119..cee72236 100644 --- a/gui/src/locales/ru.js +++ b/gui/src/locales/ru.js @@ -20,6 +20,7 @@ export default { log: "Журнал", darkTheme: "Темная тема", lightTheme: "Светлая тема", + autoTheme: "Авто тема", }, welcome: { title: "Добро пожаловать", diff --git a/gui/src/locales/zh.js b/gui/src/locales/zh.js index bf163021..0e2234cd 100644 --- a/gui/src/locales/zh.js +++ b/gui/src/locales/zh.js @@ -20,6 +20,7 @@ export default { log: "日志", darkTheme: "深色主题", lightTheme: "浅色主题", + autoTheme: "自动主题", }, welcome: { title: "初来乍到,请多关照",