Extract code into function

This commit is contained in:
RMidhunSuresh 2022-05-27 14:23:38 +05:30
parent 1f00c8f635
commit d4084da299

View file

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