simplify darkmode ui toggle.

This commit is contained in:
Jason Kulatunga
2022-06-04 20:32:12 -07:00
parent 4b767421f3
commit 2ca44c967e
5 changed files with 29 additions and 37 deletions
@@ -13,15 +13,12 @@ export class TreoConfigService
{
// Private
private _config: BehaviorSubject<any>;
private systemPrefersDark: boolean;
/**
* Constructor
*/
constructor(@Inject(TREO_APP_CONFIG) defaultConfig: any)
{
this.systemPrefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
let currentScrutinyConfig = defaultConfig
let localConfigStr = localStorage.getItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY)
@@ -30,9 +27,6 @@ export class TreoConfigService
let localConfig = JSON.parse(localConfigStr)
currentScrutinyConfig = Object.assign({}, localConfig, currentScrutinyConfig) // make sure defaults are available if missing from localStorage.
}
currentScrutinyConfig.theme = this.determineTheme(currentScrutinyConfig);
// Set the private defaults
this._config = new BehaviorSubject(currentScrutinyConfig);
}
@@ -53,8 +47,6 @@ export class TreoConfigService
//Store the config in localstorage
localStorage.setItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
config.theme = this.determineTheme(config);
// Execute the observable
this._config.next(config);
}
@@ -69,13 +61,6 @@ export class TreoConfigService
// @ Private methods
// -----------------------------------------------------------------------------------------------------
/**
* Checks if theme should be set to dark based on config & system settings
*/
private determineTheme(config:AppConfig): string {
return (config.themeUseSystem && this.systemPrefersDark) ? "dark" : config.theme;
}
// -----------------------------------------------------------------------------------------------------
// @ Public methods
// -----------------------------------------------------------------------------------------------------