mirror of
https://github.com/fmhy/edit.git
synced 2026-01-13 07:21:08 +11:00
shitty (probably not working) fix for preset themes
This commit is contained in:
parent
09e43b4954
commit
e173b8a89e
2 changed files with 25 additions and 0 deletions
|
|
@ -205,6 +205,16 @@ watch(selectedColor, async (color) => {
|
||||||
if (!color) return;
|
if (!color) return;
|
||||||
const theme = generateThemeFromColor(color)
|
const theme = generateThemeFromColor(color)
|
||||||
themeRegistry[`color-${color}`] = theme
|
themeRegistry[`color-${color}`] = theme
|
||||||
|
// Hopeful Fix For Preset Themes
|
||||||
|
try {
|
||||||
|
const key = 'vitepress-theme-data'
|
||||||
|
const raw = localStorage.getItem(key)
|
||||||
|
const parsed = raw ? JSON.parse(raw) as Record<string, any> : {}
|
||||||
|
parsed[`color-${color}`] = theme
|
||||||
|
localStorage.setItem(key, JSON.stringify(parsed))
|
||||||
|
} catch (e) {
|
||||||
|
// ignore storage errors
|
||||||
|
}
|
||||||
// Explicitly set the theme to override any previous selection
|
// Explicitly set the theme to override any previous selection
|
||||||
await nextTick()
|
await nextTick()
|
||||||
console.log('Setting theme to:', `color-${color}`)
|
console.log('Setting theme to:', `color-${color}`)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import { themeRegistry } from './configs'
|
||||||
const STORAGE_KEY_THEME = 'vitepress-theme-name'
|
const STORAGE_KEY_THEME = 'vitepress-theme-name'
|
||||||
const STORAGE_KEY_MODE = 'vitepress-display-mode'
|
const STORAGE_KEY_MODE = 'vitepress-display-mode'
|
||||||
const STORAGE_KEY_AMOLED = 'vitepress-amoled-enabled'
|
const STORAGE_KEY_AMOLED = 'vitepress-amoled-enabled'
|
||||||
|
const STORAGE_KEY_THEME_DATA = 'vitepress-theme-data'
|
||||||
|
|
||||||
export class ThemeHandler {
|
export class ThemeHandler {
|
||||||
private state = ref<ThemeState>({
|
private state = ref<ThemeState>({
|
||||||
|
|
@ -46,6 +47,20 @@ export class ThemeHandler {
|
||||||
if (themeRegistry[savedTheme]) {
|
if (themeRegistry[savedTheme]) {
|
||||||
this.state.value.currentTheme = savedTheme
|
this.state.value.currentTheme = savedTheme
|
||||||
this.state.value.theme = themeRegistry[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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set amoled preference
|
// Set amoled preference
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue