()
| 24 | } |
| 25 | |
| 26 | export function useThemeSync(): void { |
| 27 | const themeMode = useSettingStore((s) => s.themeMode); |
| 28 | |
| 29 | useEffect(() => { |
| 30 | if (themeMode === "light") { |
| 31 | applyTheme(false); |
| 32 | return; |
| 33 | } |
| 34 | if (themeMode === "dark") { |
| 35 | applyTheme(true); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | // themeMode === "auto": follow system |
| 40 | const media = window.matchMedia("(prefers-color-scheme: dark)"); |
| 41 | const update = () => applyTheme(media.matches); |
| 42 | update(); |
| 43 | media.addEventListener("change", update); |
| 44 | return () => media.removeEventListener("change", update); |
| 45 | }, [themeMode]); |
| 46 | } |
no test coverage detected