From eacba654c95185951a7c5459eebc570d001604ec Mon Sep 17 00:00:00 2001 From: JSR Date: Wed, 18 Mar 2026 18:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=BB=E9=A2=98=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=90=8E=E4=BA=8B=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/ThemeContext.tsx | 8 +++++--- src/preload/types.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/contexts/ThemeContext.tsx b/src/contexts/ThemeContext.tsx index 3f9b4e0..3a87a2b 100644 --- a/src/contexts/ThemeContext.tsx +++ b/src/contexts/ThemeContext.tsx @@ -18,13 +18,15 @@ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ childre const currentThemeRef = useRef(null) const applyThemeConfig = useCallback((theme: themeConfig) => { - const { tdesign, custom } = theme.config + if (!theme) return + const tdesign = theme.config?.tdesign || {} + const custom = theme.config?.custom || {} const root = document.documentElement const prevKeys = appliedStyleKeysRef.current for (const k of prevKeys) root.style.removeProperty(k) const nextKeys: string[] = [] - root.setAttribute("theme-mode", theme.mode) + root.setAttribute("theme-mode", theme.mode || "light") const brandColor = tdesign.brandColor || "#1677FF" const hex = brandColor.replace("#", "") @@ -38,7 +40,7 @@ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ childre nextKeys.push("--ss-primary-rgb") if (brandColor) { - const colorMap = generateColorMap(brandColor, theme.mode) + const colorMap = generateColorMap(brandColor, theme.mode || "light") Object.entries(colorMap).forEach(([key, value]) => { root.style.setProperty(key, value) nextKeys.push(key) diff --git a/src/preload/types.ts b/src/preload/types.ts index 908cd63..c39bdf3 100644 --- a/src/preload/types.ts +++ b/src/preload/types.ts @@ -53,8 +53,13 @@ const api = { deleteTheme: (themeId: string): Promise<{ success: boolean }> => invoke("theme_delete", { themeId }), onThemeChanged: (callback: (theme: themeConfig) => void): Promise => { - return listen<{ theme: themeConfig }>("theme:updated", (event) => { - callback(event.payload.theme) + return listen("theme:updated", (event) => { + const payload = event.payload as themeConfig | { theme?: themeConfig } | undefined + const theme = + payload && typeof payload === "object" && "theme" in payload + ? payload.theme + : (payload as themeConfig | undefined) + if (theme) callback(theme) }) },