Files
AstrBot/dashboard/src/App.vue
T
Kangyang Ji 7aae048405 feat(dashboard): add auto switch theme (default off) (#6405)
* feat(dashboard): add auto switch theme (default off)
feat(dashboard): move all get theme and set theme by check current theme into stores/customizer

* feat(dashboard): fix duplicate for auto switch theme
根据Gemini的意见更改了一些地方。
将原本的状态更新挪到了App.vue里,可以去除很多地方更新theme所需要的theme依赖。
将翻译修改了
将监听器改为了watch
2026-03-17 19:06:01 +08:00

66 lines
1.9 KiB
Vue

<template>
<RouterView></RouterView>
<WaitingForRestart ref="globalWaitingRef" />
<!-- 全局唯一 snackbar -->
<v-snackbar v-if="toastStore.current" v-model="snackbarShow" :color="toastStore.current.color"
:timeout="toastStore.current.timeout" :multi-line="toastStore.current.multiLine"
:location="toastStore.current.location" close-on-back>
{{ toastStore.current.message }}
<template #actions v-if="toastStore.current.closable">
<v-btn variant="text" @click="snackbarShow = false">关闭</v-btn>
</template>
</v-snackbar>
</template>
<script setup>
import { RouterView } from 'vue-router';
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useTheme } from "vuetify";
import { useToastStore } from '@/stores/toast';
import { useCustomizerStore } from '@/stores/customizer';
import WaitingForRestart from '@/components/shared/WaitingForRestart.vue';
const toastStore = useToastStore();
const theme = useTheme();
const customizer = useCustomizerStore();
const globalWaitingRef = ref(null);
let disposeTrayRestartListener = null;
const snackbarShow = computed({
get: () => !!toastStore.current,
set: (val) => {
if (!val) toastStore.shift()
}
});
// 统一监听 uiTheme 变化并同步到 Vuetify
watch(() => customizer.uiTheme, (newTheme) => {
if (newTheme) {
theme.global.name.value = newTheme;
}
}, { immediate: true });
onMounted(() => {
const desktopBridge = window.astrbotDesktop
if (!desktopBridge?.onTrayRestartBackend) {
return
}
disposeTrayRestartListener = desktopBridge.onTrayRestartBackend(async () => {
try {
await globalWaitingRef.value?.check?.()
} catch (error) {
globalWaitingRef.value?.stop?.()
console.error('Tray restart backend failed:', error)
}
})
})
onBeforeUnmount(() => {
if (disposeTrayRestartListener) {
disposeTrayRestartListener()
disposeTrayRestartListener = null
}
})
</script>