Extract code into function

This commit is contained in:
RMidhunSuresh 2022-05-27 14:23:38 +05:30
parent 1f00c8f635
commit d4084da299
1 changed files with 5 additions and 4 deletions

View File

@ -79,18 +79,19 @@ export class ThemeLoader {
}
async getActiveTheme(): Promise<string> {
// check if theme is set via settings
let theme = await this._platform.settingsStorage.getString("theme");
const theme = await this._platform.settingsStorage.getString("theme") ?? this.getDefaultTheme();
if (theme) {
return theme;
}
// return default theme
throw new Error("Cannot find active theme!");
}
getDefaultTheme(): string | undefined {
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
return this._platform.config["defaultTheme"].dark;
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
return this._platform.config["defaultTheme"].light;
}
throw new Error("Cannot find active theme!");
}
private _findThemeLocationFromId(themeId: string) {