forked from mystiq/hydrogen-web
Extract code into function
This commit is contained in:
parent
1f00c8f635
commit
d4084da299
1 changed files with 5 additions and 4 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue