From 854e9f61c4a931f71e56a297db62795998f864bd Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Sun, 30 Jun 2019 16:06:06 +0000 Subject: [PATCH] Make mode setting code clearer This should clear up some confusion with the way that I had implemented mode setting, making the code more readable. --- assets/js/themes.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/js/themes.js b/assets/js/themes.js index 587a1434..9388d422 100644 --- a/assets/js/themes.js +++ b/assets/js/themes.js @@ -38,12 +38,15 @@ function set_mode (bool) { } function update_mode (mode) { - set_mode( - mode == 'true' // for backwards compatibility - || mode == 'dark' - || (mode != 'light' - && window.matchMedia('(prefers-color-scheme: dark)').matches) - ); + if (mode == 'true' /* for backwards compatibility */ || mode == 'dark') { + // If dark mode preference set + set_mode(true); + } + else if (mode != 'light' && window.matchMedia('(prefers-color-scheme: dark)').matches) { + // If no preference set, but the browser tells us that the operating system has a dark theme + set_mode(true); + } + else set_mode(false); }