Skip to content

Commit

Permalink
Polish 'Fix dark scheme detect function'
Browse files Browse the repository at this point in the history
See gh-23

Closes gh-23
  • Loading branch information
philwebb committed Jun 10, 2021
1 parent d0e44ad commit caa0a60
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/main/js/setup/switchtheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

const localStorage = window.localStorage;
const htmlElement = document.documentElement;
const prefersDarkColorScheme = window.matchMedia(
"(prefers-color-scheme: dark)"
);

swithInitialTheme();
window.addEventListener("load", onWindowLoad);
Expand All @@ -43,18 +46,8 @@
}

function isInitialThemeDark() {
const prefersDarkColorScheme = window.matchMedia(
"(prefers-color-scheme: dark)"
);
const savedColorScheme = loadTheme();
switch (savedColorScheme) {
case "dark":
return true;
case "light":
return false;
default:
return prefersDarkColorScheme.matches;
}
const theme = loadTheme();
return theme ? theme === "dark" : prefersDarkColorScheme.matches;
}

function onThemeChange() {
Expand Down

0 comments on commit caa0a60

Please sign in to comment.