-
Notifications
You must be signed in to change notification settings - Fork 103
/
shouldBeDarkMode.ts
28 lines (26 loc) · 966 Bytes
/
shouldBeDarkMode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { AppTheme } from '../enums'
/**
* NOTE: This media query is performed only once to help make the UX
* consistent across OS platforms. To be specific, it ensures that users
* are required to restart Firefly for system theme changes to take effect.
* This is because the behaviour of this media query is different among platforms,
* e.g. queries on MacOS result in up-to-date information whereas Linux-based platforms
* result in stale information.
*/
const IS_SYSTEM_IN_DARK_MODE = window.matchMedia('(prefers-color-scheme: dark)').matches
/**
* Returns true if the application should be in dark mode based off of
* a given theme.
*/
export const shouldBeDarkMode = (theme: AppTheme): boolean => {
switch (theme) {
case AppTheme.Light:
return false
case AppTheme.Dark:
return true
case AppTheme.System:
return IS_SYSTEM_IN_DARK_MODE
default:
return false
}
}