use os detection for initial dark mode setting

This commit is contained in:
David Lechner
2021-01-15 10:54:57 -06:00
parent 8f71ace56d
commit b38a47f4e6
3 changed files with 39 additions and 1 deletions
+16
View File
@@ -3,6 +3,22 @@
// Utility functions for dealing with operating systems.
/**
* Tests if we are running on macOS.
* @returns `true` if running on macOS, otherwise `false`.
*/
export function isMacOS(): boolean {
return /mac/i.test(navigator.platform);
}
/**
* Tests if the OS is set to dark mode.
* @returns: `true` if dark mode should be preferred, otherwise `false`.
*/
export function prefersDarkMode(): boolean {
if (!window.matchMedia) {
return false;
}
return window.matchMedia('(prefers-color-scheme: dark)').matches;
}