mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-08 18:48:18 +01:00
Extract code into function
This commit is contained in:
parent
1f00c8f635
commit
d4084da299
@ -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…
x
Reference in New Issue
Block a user