Fix blink when loading with dark mode

This commit is contained in:
Andras Schmelczer 2022-09-23 22:47:49 +02:00
parent 4ca000b7a3
commit fb3786f703
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E

View file

@ -9,20 +9,18 @@ export class PageThemeSwitcher extends PageElement {
super(createElement(generate()));
const storedIsDark = PageThemeSwitcher.loadFromLocalStorage();
const isDark = storedIsDark !== null ? storedIsDark : isSystemLevelDarkModeEnabled();
const isDark = storedIsDark ?? isSystemLevelDarkModeEnabled();
if (isDark) {
(this.htmlRoot as HTMLInputElement).checked = true;
turnOffAnimations();
turnOnDarkMode();
turnOnAnimations();
setTimeout(turnOnAnimations, 0);
} else {
turnOnLightMode();
}
this.htmlRoot.onchange = this.handleThemeChange.bind(this);
this.handleThemeChange();
}
private handleThemeChange() {