feat: improve web mode notification (#309)

This commit is contained in:
josc146
2023-05-08 15:50:42 +08:00
parent b487c03ab3
commit e95372d77d
12 changed files with 107 additions and 49 deletions
+8
View File
@@ -0,0 +1,8 @@
import { useConfig } from './use-config.mjs'
import { useWindowTheme } from './use-window-theme.mjs'
export function useTheme() {
const config = useConfig()
const theme = useWindowTheme()
return [config.themeMode === 'auto' ? theme : config.themeMode, config]
}
+4 -2
View File
@@ -2,8 +2,10 @@ import { useEffect, useState } from 'react'
export function useWindowTheme() {
const [theme, setTheme] = useState(
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
window.matchMedia
? window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light'
: 'light',
)
useEffect(() => {