This commit is contained in:
Samidy 2025-12-20 14:45:26 +03:00
parent e173b8a89e
commit b41e6b3c9b
2 changed files with 3 additions and 25 deletions

View file

@ -21,7 +21,6 @@ import { themeRegistry } from './configs'
const STORAGE_KEY_THEME = 'vitepress-theme-name'
const STORAGE_KEY_MODE = 'vitepress-display-mode'
const STORAGE_KEY_AMOLED = 'vitepress-amoled-enabled'
const STORAGE_KEY_THEME_DATA = 'vitepress-theme-data'
export class ThemeHandler {
private state = ref<ThemeState>({
@ -43,24 +42,13 @@ export class ThemeHandler {
const savedMode = localStorage.getItem(STORAGE_KEY_MODE) as DisplayMode | null
const savedAmoled = localStorage.getItem(STORAGE_KEY_AMOLED) === 'true'
// Set theme
if (themeRegistry[savedTheme]) {
this.state.value.currentTheme = savedTheme
this.state.value.theme = themeRegistry[savedTheme]
} else {
try {
const raw = localStorage.getItem(STORAGE_KEY_THEME_DATA)
if (raw) {
const parsed = JSON.parse(raw) as Record<string, any>
if (parsed && parsed[savedTheme]) {
themeRegistry[savedTheme] = parsed[savedTheme]
this.state.value.currentTheme = savedTheme
this.state.value.theme = parsed[savedTheme]
}
}
} catch (e) {
// ignore parse errors
}
localStorage.removeItem(STORAGE_KEY_THEME)
this.state.value.currentTheme = 'christmas'
this.state.value.theme = themeRegistry.christmas
}
// Set amoled preference