Saving theme in local storage

This commit is contained in:
Piotr Pekala 2019-11-28 05:25:07 -08:00
parent 6870f707bf
commit f9af6e32be
3 changed files with 9 additions and 2 deletions

View File

@ -28,6 +28,11 @@ export class AppComponent implements OnInit {
this.electronService.ipcRenderer.send('settings.changed', settings); this.electronService.ipcRenderer.send('settings.changed', settings);
}); });
} }
let theme = localStorage.getItem('theme');
if (theme === 'light') {
this.themeService.setDarkMode(false);
} else {
this.themeService.setDarkMode(true); this.themeService.setDarkMode(true);
} }
}
} }

View File

@ -32,6 +32,5 @@ export class SettingsComponent implements OnInit {
setDarkMode(value: boolean) { setDarkMode(value: boolean) {
this.themeService.setDarkMode(value); this.themeService.setDarkMode(value);
//this value should be saved and stored in local memory
} }
} }

View File

@ -41,12 +41,15 @@ export class ThemeService {
setDarkMode(value: boolean) { setDarkMode(value: boolean) {
this._darkMode$.next(value); this._darkMode$.next(value);
localStorage.removeItem('theme');
if (value) { if (value) {
this.savedTheme = 'dark'; this.savedTheme = 'dark';
this.themeChanged.emit(this.savedTheme); this.themeChanged.emit(this.savedTheme);
localStorage.setItem('theme', 'dark');
} else { } else {
this.savedTheme = 'light'; this.savedTheme = 'light';
this.themeChanged.emit(this.savedTheme); this.themeChanged.emit(this.savedTheme);
localStorage.setItem('theme', 'light');
} }
} }