Skip to content

Commit caa0a60

Browse files
committed
Polish 'Fix dark scheme detect function'
See gh-23 Closes gh-23
1 parent d0e44ad commit caa0a60

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/main/js/setup/switchtheme.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
const localStorage = window.localStorage;
2323
const htmlElement = document.documentElement;
24+
const prefersDarkColorScheme = window.matchMedia(
25+
"(prefers-color-scheme: dark)"
26+
);
2427

2528
swithInitialTheme();
2629
window.addEventListener("load", onWindowLoad);
@@ -43,18 +46,8 @@
4346
}
4447

4548
function isInitialThemeDark() {
46-
const prefersDarkColorScheme = window.matchMedia(
47-
"(prefers-color-scheme: dark)"
48-
);
49-
const savedColorScheme = loadTheme();
50-
switch (savedColorScheme) {
51-
case "dark":
52-
return true;
53-
case "light":
54-
return false;
55-
default:
56-
return prefersDarkColorScheme.matches;
57-
}
49+
const theme = loadTheme();
50+
return theme ? theme === "dark" : prefersDarkColorScheme.matches;
5851
}
5952

6053
function onThemeChange() {

0 commit comments

Comments
 (0)