color scheme: Use the users prefered colour scheme if one isn't defined in the store

This commit is contained in:
Phil Reid 2026-06-23 08:28:15 +08:00
parent ec845c61cd
commit 287f1c6caf
1 changed files with 10 additions and 4 deletions

View File

@ -21,10 +21,16 @@ export function localStorageColorSchemeManager({
}
try {
return (
(window.localStorage.getItem(key) as MantineColorScheme) ||
defaultValue
);
const storedValue = window.localStorage.getItem(key);
// If a value exists in storage, return it
if (storedValue && isMantineColorScheme(storedValue)) {
return storedValue;
}
// If no value, check the system preference
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
return systemPrefersDark ? 'dark' : 'light';
} catch {
return defaultValue;
}