Skip to content

Commit

Permalink
Merge pull request #2179 from shinyichen/darkmode-fix
Browse files Browse the repository at this point in the history
Fixed dark mode setting logic error.
  • Loading branch information
thostetler authored Jun 11, 2021
2 parents 55370f2 + ea84b0b commit 8459c1a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/js/dark-mode-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ define(['analytics'], function(analytics) {
darkSwitch = document.getElementById('darkSwitch');

// 1. check app setting
if (
localStorage.getItem('darkSwitch') !== null &&
localStorage.getItem('darkSwitch') === 'on'
) {
turnOnDarkMode(false);
}
// 2. check system setting
else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (localStorage.getItem('darkSwitch') !== null) {
if (localStorage.getItem('darkSwitch') === 'on') {
turnOnDarkMode(false);
} else {
turnOffDarkMode(false);
}
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
// 2. check system setting
turnOnDarkMode(false);
} else {
// 3. default to light
turnOffDarkMode(false);
}
darkSwitch.addEventListener('click', function() {
Expand Down

0 comments on commit 8459c1a

Please sign in to comment.