Fix system theme not working on load

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-01-07 10:21:35 +05:30
parent be905ac7be
commit ca3cced6ad

View file

@ -48,11 +48,19 @@ class Settings extends EventEmitter {
setTheme(themeIndex) { setTheme(themeIndex) {
const appBody = document.getElementById('appBody'); const appBody = document.getElementById('appBody');
appBody.classList.remove('system-theme');
this.themes.forEach((themeName) => { this.themes.forEach((themeName) => {
if (themeName === '') return; if (themeName === '') return;
appBody.classList.remove(themeName); appBody.classList.remove(themeName);
}); });
if (this.themes[themeIndex] !== '') appBody.classList.add(this.themes[themeIndex]); // If use system theme is enabled
// we will override current theme choice with system theme
if (this.useSystemTheme) {
appBody.classList.add('system-theme');
} else if (this.themes[themeIndex] !== '') {
appBody.classList.add(this.themes[themeIndex]);
}
setSettings('themeIndex', themeIndex); setSettings('themeIndex', themeIndex);
this.themeIndex = themeIndex; this.themeIndex = themeIndex;
} }
@ -106,19 +114,9 @@ class Settings extends EventEmitter {
const actions = { const actions = {
[cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => { [cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => {
this.useSystemTheme = !this.useSystemTheme; this.useSystemTheme = !this.useSystemTheme;
setSettings('useSystemTheme', this.useSystemTheme);
const appBody = document.getElementById('appBody');
if (this.useSystemTheme) { setSettings('useSystemTheme', this.useSystemTheme);
appBody.classList.add('system-theme'); this.setTheme(this.themeIndex);
this.themes.forEach((themeName) => {
if (themeName === '') return;
appBody.classList.remove(themeName);
});
} else {
appBody.classList.remove('system-theme');
this.setTheme(this.themeIndex);
}
this.emit(cons.events.settings.SYSTEM_THEME_TOGGLED, this.useSystemTheme); this.emit(cons.events.settings.SYSTEM_THEME_TOGGLED, this.useSystemTheme);
}, },