theme.ts
Language TypeScript1.3 KB28 lines
import { useEffect } from 'react'import type { Settings } from '../ipc/gen/Settings'/** Resolve the theme and transparency settings onto <html>. */export function useTheme(settings: Settings | null, vibrancy: boolean) {useEffect(() => {const root = document.documentElementconst media = window.matchMedia('(prefers-color-scheme: dark)')const apply = () => {const pref = settings?.theme ?? 'system'root.dataset.theme = pref === 'system' ? (media.matches ? 'dark' : 'light') : prefroot.dataset.vibrancy = vibrancy ? 'native' : 'none'root.dataset.reduceTransparency = String(!!settings?.reduce_transparency)root.style.setProperty('--tint', String((settings?.glass_tint ?? 100) / 100))}apply()media.addEventListener('change', apply)return () => media.removeEventListener('change', apply)}, [settings?.theme, settings?.reduce_transparency, settings?.glass_tint, vibrancy])}export const isMac = typeof navigator !== 'undefined' && /Mac/i.test(navigator.platform || navigator.userAgent)export const mod = isMac ? '⌘' : 'Ctrl+'/** The quick window's height with no answer, and the most it grows to: `QUICK_HEIGHT` and `QUICK_MAX` in windows.rs. */export const QUICK_HEIGHT = 76export const QUICK_MAX = 560