Added theme to local storage for saving/loading.

This commit is contained in:
Tom 2025-04-02 16:27:06 +00:00
parent 5489eb4df6
commit 1e6690ff4b
2 changed files with 11 additions and 0 deletions

View File

@ -105,6 +105,12 @@ export class AppComponent implements OnInit, OnDestroy {
}); });
})); }));
let currentTheme = localStorage.getItem('ui-theme') ?? this.themeService.theme;
if (currentTheme == 'light' || currentTheme == 'dark') {
this.themeService.theme = currentTheme;
} else {
this.themeService.theme = 'dark';
}
this.overlayContainer.getContainerElement().classList.add(this.themeService.theme + '-theme'); this.overlayContainer.getContainerElement().classList.add(this.themeService.theme + '-theme');
this.addSubscription(this.events.listen('theme_change', data => { this.addSubscription(this.events.listen('theme_change', data => {

View File

@ -14,7 +14,12 @@ export class ThemeService {
set theme(value: 'light' | 'dark') { set theme(value: 'light' | 'dark') {
const previous = this._current(); const previous = this._current();
if (previous == value) {
return;
}
this._current.set(value); this._current.set(value);
localStorage.setItem('ui-theme', value);
this.events.emit('theme_change', { this.events.emit('theme_change', {
previous_theme: previous, previous_theme: previous,
current_theme: value, current_theme: value,