Files
AstrBot/dashboard/src/stores/customizer.ts
lingyun14 d2b86c5991 feat(dashboard): add a configurable theme mode with light, dark, and system options and centralize theme synchronization with system preferences. (#8648)
* Update main.ts

* Update config.ts

* Update header.json

* Update auth.json

* Update header.json

* Update auth.json

* Update header.json

* Update auth.json

* Update VerticalHeader.vue

* Update customizer.ts

* Update LoginPage.vue

* Update SetupPage.vue

* Update config.ts

* Update customizer.ts

* Update plugin-pages.md

* docs: add Follow System note to plugin-pages theme section
2026-06-13 16:41:54 +08:00

58 lines
1.6 KiB
TypeScript

import { defineStore } from 'pinia';
import config, { type ThemeMode, resolveUiTheme } from '@/config';
const DARK_THEMES: ReadonlySet<string> = new Set(['PurpleThemeDark']);
export const useCustomizerStore = defineStore('customizer', {
state: () => ({
Sidebar_drawer: config.Sidebar_drawer,
Customizer_drawer: config.Customizer_drawer,
mini_sidebar: config.mini_sidebar,
fontTheme: 'Noto Sans SC',
uiTheme: config.uiTheme,
themeMode: config.themeMode as ThemeMode,
inputBg: config.inputBg,
chatSidebarOpen: false, // chat mode mobile sidebar state
}),
getters: {
isDark: (state) => state.uiTheme ? DARK_THEMES.has(state.uiTheme) : false,
},
actions: {
SET_SIDEBAR_DRAWER() {
this.Sidebar_drawer = !this.Sidebar_drawer;
},
SET_MINI_SIDEBAR(payload: boolean) {
this.mini_sidebar = payload;
},
SET_FONT(payload: string) {
this.fontTheme = payload;
},
SET_UI_THEME(payload: string) {
this.uiTheme = payload;
localStorage.setItem('uiTheme', payload);
const mode: ThemeMode = payload === 'PurpleThemeDark' ? 'dark' : 'light';
this.themeMode = mode;
localStorage.setItem('themeMode', mode);
},
SET_THEME_MODE(mode: ThemeMode) {
this.themeMode = mode;
localStorage.setItem('themeMode', mode);
const uiTheme = resolveUiTheme(mode);
this.uiTheme = uiTheme;
localStorage.setItem('uiTheme', uiTheme);
},
TOGGLE_CHAT_SIDEBAR() {
this.chatSidebarOpen = !this.chatSidebarOpen;
},
SET_CHAT_SIDEBAR(payload: boolean) {
this.chatSidebarOpen = payload;
},
},
});