1
Fork 0

Add support for "always theme" in setting

This commit is contained in:
Jacob Hoffman-Andrews 2022-01-07 18:21:08 -05:00
parent c4b994ff80
commit 04f04026c5
4 changed files with 47 additions and 10 deletions

View file

@ -187,22 +187,25 @@ var updateSystemTheme = (function() {
var mql = window.matchMedia("(prefers-color-scheme: dark)");
function handlePreferenceChange(mql) {
let use = function(theme) {
switchTheme(window.currentTheme, window.mainTheme, theme, true);
};
// maybe the user has disabled the setting in the meantime!
if (getSettingValue("use-system-theme") !== "false") {
var lightTheme = getSettingValue("preferred-light-theme") || "light";
var darkTheme = getSettingValue("preferred-dark-theme") || "dark";
if (mql.matches) {
// prefers a dark theme
switchTheme(window.currentTheme, window.mainTheme, darkTheme, true);
use(darkTheme);
} else {
// prefers a light theme, or has no preference
switchTheme(window.currentTheme, window.mainTheme, lightTheme, true);
use(lightTheme);
}
// note: we save the theme so that it doesn't suddenly change when
// the user disables "use-system-theme" and reloads the page or
// navigates to another page
} else {
use(getSettingValue("theme"));
}
}