feat: implement theme synchronization and loading skeletons across various components, enhancing user experience during content loading

This commit is contained in:
wizardchen
2026-04-11 15:03:20 +08:00
committed by lyingbug
parent 1a4b7b390d
commit 6d8b47e57c
15 changed files with 441 additions and 19 deletions
+37
View File
@@ -13,9 +13,46 @@ function getSystemTheme(): 'light' | 'dark' {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
/** Wails:与原生窗口底色 / 系统深浅色一致,减轻 Ctrl+R 整窗白闪(浅色与 --td-bg-color-page #eee 对齐) */
function syncWailsNativeChrome(effective: 'light' | 'dark') {
const bg = effective === 'dark' ? '#181818' : '#eeeeee'
document.documentElement.style.background = bg
document.documentElement.style.minHeight = '100%'
document.documentElement.style.colorScheme = effective === 'dark' ? 'dark' : 'light'
if (document.body) {
document.body.style.background = bg
document.body.style.minHeight = '100%'
}
const appEl = document.getElementById('app')
if (appEl) {
appEl.style.background = bg
appEl.style.minHeight = '100%'
}
const w = (window as unknown as {
runtime?: {
WindowSetDarkTheme?: () => void
WindowSetLightTheme?: () => void
WindowSetBackgroundColour?: (r: number, g: number, b: number, a: number) => void
}
}).runtime
if (!w?.WindowSetBackgroundColour) return
try {
if (effective === 'dark') {
w.WindowSetDarkTheme?.()
w.WindowSetBackgroundColour(24, 24, 24, 255)
} else {
w.WindowSetLightTheme?.()
w.WindowSetBackgroundColour(238, 238, 238, 255)
}
} catch {
/* 非桌面壳或未注入 runtime */
}
}
function applyTheme(mode: ThemeMode) {
const effective = mode === 'system' ? getSystemTheme() : mode
document.documentElement.setAttribute('theme-mode', effective)
syncWailsNativeChrome(effective)
}
export function useTheme() {