From f289ede15e5a7eb6335fb9bb2df4d40ba060eb84 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Mon, 2 Mar 2026 23:09:02 +0100 Subject: [PATCH] fix: add isDark to useThemeManager return value --- src/hooks/useThemeManager.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hooks/useThemeManager.ts b/src/hooks/useThemeManager.ts index 7906e437..a4f2aa5f 100644 --- a/src/hooks/useThemeManager.ts +++ b/src/hooks/useThemeManager.ts @@ -187,5 +187,17 @@ export function useThemeManager( const reloadThemes = useCallback(async () => { await reload() }, [reload]) - return { themes, activeThemeId, activeTheme, switchTheme, createTheme, reloadThemes } + // Determine if the active theme is dark by checking --background CSS variable + const isDark = useMemo(() => { + if (!activeThemeId || !cachedThemeContent) return false + const vars = extractCssVars(cachedThemeContent) + const bg = vars['--background'] ?? '' + if (!bg.startsWith('#') || bg.length < 7) return false + const r = parseInt(bg.slice(1, 3), 16) + const g = parseInt(bg.slice(3, 5), 16) + const b = parseInt(bg.slice(5, 7), 16) + return (0.299 * r + 0.587 * g + 0.114 * b) / 255 < 0.5 + }, [activeThemeId, cachedThemeContent]) + + return { themes, activeThemeId, activeTheme, isDark, switchTheme, createTheme, reloadThemes } }