Add pure black mode option

This commit is contained in:
schroda
2024-09-05 00:08:23 +02:00
parent ba2ce37468
commit 1444d51ed2
6 changed files with 37 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ import useMediaQuery from '@mui/material/useMediaQuery';
import { Breakpoint } from '@mui/material/styles';
import { getCurrentTheme } from '@/theme.ts';
import { ThemeMode } from '@/components/context/ThemeModeContext.tsx';
import { AppStorage } from '@/util/AppStorage.ts';
export class MediaQuery {
static useIsTouchDevice(): boolean {
@@ -29,6 +30,17 @@ export class MediaQuery {
return prefersDarkMode ? ThemeMode.DARK : ThemeMode.LIGHT;
}
static getThemeMode(): Exclude<ThemeMode, 'system'> {
const themeMode = AppStorage.local.getItemParsed<ThemeMode>('themeMode', ThemeMode.SYSTEM);
const isSystemMode = themeMode === ThemeMode.SYSTEM;
if (isSystemMode) {
return this.getSystemThemeMode();
}
return themeMode;
}
static listenToSystemThemeChange(onChange: (themeMode: Exclude<ThemeMode, 'system'>) => void): () => void {
const handleSystemThemeModeChange = (e: MediaQueryListEvent) => {
onChange(e.matches ? ThemeMode.DARK : ThemeMode.LIGHT);