-
-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(dashboard): add auto-switch light and dark button #7527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kyangconn
wants to merge
5
commits into
AstrBotDevs:master
Choose a base branch
from
kyangconn:feat/auto-switch-button
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74b57d4
feat(dashboard): enhance types and theme management in Settings.vue
kyangconn bbf0576
rfc(theme): refactor themetypes and presets to types/theme.ts
kyangconn 5cbcb9e
rfc(dashboard): refactor Setting page, move theme card to single temp…
kyangconn e5b2e2d
fix: move all light and dark mode management into customizer
kyangconn f02b7ca
fix: auto switching not work
kyangconn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+384 Bytes
(100%)
dashboard/src/assets/mdi-subset/materialdesignicons-webfont-subset.woff
Binary file not shown.
Binary file modified
BIN
+384 Bytes
(100%)
dashboard/src/assets/mdi-subset/materialdesignicons-webfont-subset.woff2
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| <template> | ||
| <!-- Row 1: Preset selector + theme mode --> | ||
| <div class="d-flex flex-wrap align-center ga-4 mb-4 ml-3"> | ||
| <v-select v-model="selectedThemePreset" :items="presetOptions" :label="tm('theme.customize.preset')" hide-details | ||
| variant="outlined" density="compact" style="min-width: 200px; max-width: 280px" | ||
| @update:model-value="applyThemePreset" /> | ||
| <v-btn-toggle v-model="themeMode" mandatory density="compact" color="primary"> | ||
| <v-btn value="light" size="small"> | ||
| <v-icon class="mr-1" size="18">mdi-white-balance-sunny</v-icon> | ||
| {{ tm("theme.customize.light") }} | ||
| </v-btn> | ||
| <v-btn value="dark" size="small"> | ||
| <v-icon class="mr-1" size="18">mdi-moon-waning-crescent</v-icon> | ||
| {{ tm("theme.customize.dark") }} | ||
| </v-btn> | ||
| <v-btn value="auto" size="small"> | ||
| <v-icon class="mr-1" size="18">mdi-sync</v-icon> | ||
| {{ tm("theme.customize.auto") }} | ||
| </v-btn> | ||
| </v-btn-toggle> | ||
| <v-tooltip location="top"> | ||
| <template #activator="{ props }"> | ||
| <v-icon v-bind="props" size="16" color="primary" class="ml-1">mdi-help-circle-outline</v-icon> | ||
| </template> | ||
| <span>{{ tm("theme.customize.autoSwitchDesc") }}</span> | ||
| </v-tooltip> | ||
| </div> | ||
|
|
||
| <!-- Row 2: Color pickers + reset --> | ||
| <v-card variant="outlined" class="pa-3"> | ||
| <div class="text-body-2 text-medium-emphasis mb-3"> | ||
| {{ tm("theme.customize.colors") }} | ||
| </div> | ||
| <div class="d-flex flex-wrap align-center ga-4"> | ||
| <div class="d-flex align-center ga-3"> | ||
| <v-text-field v-model="primaryColor" type="color" :label="tm('theme.customize.primary')" hide-details | ||
| variant="outlined" density="compact" style="width: 140px" /> | ||
| <div class="color-preview" :style="{ backgroundColor: primaryColor }" /> | ||
| </div> | ||
| <div class="d-flex align-center ga-3"> | ||
| <v-text-field v-model="secondaryColor" type="color" :label="tm('theme.customize.secondary')" hide-details | ||
| variant="outlined" density="compact" style="width: 140px" /> | ||
| <div class="color-preview" :style="{ backgroundColor: secondaryColor }" /> | ||
| </div> | ||
| <v-btn size="small" variant="tonal" color="primary" @click="resetThemeColors"> | ||
| <v-icon class="mr-1" size="16">mdi-restore</v-icon> | ||
| {{ tm("theme.customize.reset") }} | ||
| </v-btn> | ||
| </div> | ||
| </v-card> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed, ref, watch } from 'vue'; | ||
| import { useModuleI18n } from "@/i18n/composables"; | ||
| import { useTheme } from "vuetify"; | ||
| import { PurpleTheme } from "@/theme/LightTheme"; | ||
| import { | ||
| LIGHT_THEME_NAME, | ||
| DARK_THEME_NAME, | ||
| themePresets, | ||
| } from "@/theme/constants"; | ||
| import type { ThemeMode } from "@/types/theme"; | ||
| import { useToastStore } from "@/stores/toast"; | ||
| import { useCustomizerStore } from "@/stores/customizer"; | ||
|
|
||
|
|
||
| const { tm } = useModuleI18n("features/settings"); | ||
| const toastStore = useToastStore(); | ||
| const theme = useTheme(); | ||
| const customizer = useCustomizerStore(); | ||
|
|
||
| // Theme mode toggle (light/dark/auto) | ||
| const themeMode = computed({ | ||
| get() { | ||
| if (customizer.autoSwitchTheme) return "auto"; | ||
| return customizer.isDarkTheme ? "dark" : "light"; | ||
| }, | ||
| set(mode: ThemeMode) { | ||
| if (mode === "auto") { | ||
| customizer.SET_AUTO_SYNC(true); | ||
| customizer.APPLY_SYSTEM_THEME(); | ||
| return; | ||
| } | ||
|
|
||
| customizer.SET_AUTO_SYNC(false); | ||
| const newTheme = mode === "dark" ? DARK_THEME_NAME : LIGHT_THEME_NAME; | ||
| customizer.SET_UI_THEME(newTheme); | ||
| }, | ||
| }); | ||
|
|
||
| const getStoredColor = (key: string, fallback: string) => { | ||
| const stored = | ||
| typeof window !== "undefined" ? localStorage.getItem(key) : null; | ||
| return stored || fallback; | ||
| }; | ||
|
|
||
| const primaryColor = ref( | ||
| getStoredColor("themePrimary", PurpleTheme.colors.primary), | ||
| ); | ||
| const secondaryColor = ref( | ||
| getStoredColor("themeSecondary", PurpleTheme.colors.secondary), | ||
| ); | ||
|
|
||
| // Get stored preset or default to blue-business name | ||
| const selectedThemePreset = ref( | ||
| localStorage.getItem("themePreset") || themePresets[0].name, | ||
| ); | ||
|
|
||
| // Simple array for dropdown display | ||
| const presetOptions = themePresets.map((p) => p.name); | ||
|
|
||
| const applyThemePreset = (presetName: string) => { | ||
| const preset = themePresets.find((p) => p.name === presetName); | ||
| if (!preset) return; | ||
|
|
||
| // Store the preset selection (store by name for display consistency) | ||
| localStorage.setItem("themePreset", presetName); | ||
| selectedThemePreset.value = presetName; | ||
|
|
||
| // Update primary and secondary colors | ||
| primaryColor.value = preset.primary; | ||
| secondaryColor.value = preset.secondary; | ||
| localStorage.setItem("themePrimary", preset.primary); | ||
| localStorage.setItem("themeSecondary", preset.secondary); | ||
|
|
||
| // Apply to themes | ||
| applyThemeColors(preset.primary, preset.secondary); | ||
|
|
||
| toastStore.add({ | ||
| message: tm("theme.customize.presetApplied") || "主题已应用", | ||
| color: "success", | ||
| }); | ||
| }; | ||
|
|
||
| const resolveThemes = () => { | ||
| if (theme?.themes?.value) return theme.themes.value as Record<string, any>; | ||
| return null; | ||
| }; | ||
|
|
||
| const applyThemeColors = (primary: string, secondary: string) => { | ||
| const themes = resolveThemes(); | ||
| if (!themes) return; | ||
| [LIGHT_THEME_NAME, DARK_THEME_NAME].forEach((name) => { | ||
| const themeDef = themes[name]; | ||
| if (!themeDef?.colors) return; | ||
| if (primary) themeDef.colors.primary = primary; | ||
| if (secondary) themeDef.colors.secondary = secondary; | ||
| if (primary && themeDef.colors.darkprimary) | ||
| themeDef.colors.darkprimary = primary; | ||
| if (secondary && themeDef.colors.darksecondary) | ||
| themeDef.colors.darksecondary = secondary; | ||
| }); | ||
| }; | ||
|
|
||
| applyThemeColors(primaryColor.value, secondaryColor.value); | ||
|
|
||
| watch(primaryColor, (value) => { | ||
| if (!value) return; | ||
| localStorage.setItem("themePrimary", value); | ||
| applyThemeColors(value, secondaryColor.value); | ||
| }); | ||
|
|
||
| watch(secondaryColor, (value) => { | ||
| if (!value) return; | ||
| localStorage.setItem("themeSecondary", value); | ||
| applyThemeColors(primaryColor.value, value); | ||
| }); | ||
|
|
||
| const resetThemeColors = () => { | ||
| primaryColor.value = PurpleTheme.colors.primary; | ||
| secondaryColor.value = PurpleTheme.colors.secondary; | ||
| localStorage.removeItem("themePrimary"); | ||
| localStorage.removeItem("themeSecondary"); | ||
| applyThemeColors(primaryColor.value, secondaryColor.value); | ||
| }; | ||
|
|
||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly modifying the
themeDef.colorsobject properties might not reliably trigger reactivity in all Vuetify components if thethemesobject is not deeply reactive. A more robust approach in Vuetify 3 is to replace the entirecolorsobject or use thetheme.themes.value[name].colors = { ... }pattern to ensure the change is propagated correctly. Additionally,darkprimaryanddarksecondaryare not standard Vuetify color keys; ensure these are explicitly defined in your theme configuration if they are intended for use.