mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
gui: add auto switch theme
This commit is contained in:
1 parent
bb9bea7fa4
commit
8cd9934593
6 files changed
+32
-9
No files matched your search
+27
-9
@@ -59,7 +59,7 @@
|
||||
</b-navbar-item>
|
||||
<b-navbar-item tag="a" @click.native="toggleTheme">
|
||||
<i
|
||||
:class="isDarkTheme ? 'mdi mdi-weather-sunny' : 'mdi mdi-weather-night'"
|
||||
:class="themePreference === 'auto' ? 'mdi mdi-theme-light-dark' : (isDarkTheme ? 'mdi mdi-weather-sunny' : 'mdi mdi-weather-night')"
|
||||
style="font-size: 1.25em"
|
||||
></i>
|
||||
{{ 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() {
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
log: "Logs",
|
||||
darkTheme: "Dark Theme",
|
||||
lightTheme: "Light Theme",
|
||||
autoTheme: "Auto Theme",
|
||||
},
|
||||
welcome: {
|
||||
title: "Welcome",
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
log: "گزارش ها",
|
||||
darkTheme: "تم تیره",
|
||||
lightTheme: "تم روشن",
|
||||
autoTheme: "تم خودکار",
|
||||
},
|
||||
welcome: {
|
||||
title: "خوش آمدی",
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
log: "Logs",
|
||||
darkTheme: "Tema Escuro",
|
||||
lightTheme: "Tema Claro",
|
||||
autoTheme: "Tema Automático",
|
||||
},
|
||||
welcome: {
|
||||
title: "Bem-vindo",
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
log: "Журнал",
|
||||
darkTheme: "Темная тема",
|
||||
lightTheme: "Светлая тема",
|
||||
autoTheme: "Авто тема",
|
||||
},
|
||||
welcome: {
|
||||
title: "Добро пожаловать",
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
log: "日志",
|
||||
darkTheme: "深色主题",
|
||||
lightTheme: "浅色主题",
|
||||
autoTheme: "自动主题",
|
||||
},
|
||||
welcome: {
|
||||
title: "初来乍到,请多关照",
|
||||
|
||||
Reference in new issue
Block a user