forked from mystiq/hydrogen-web
Move code to ThemeLoader
This commit is contained in:
parent
654e83a5f9
commit
0984aeb570
2 changed files with 4 additions and 15 deletions
|
@ -316,15 +316,6 @@ export class Platform {
|
|||
return this._themeLoader;
|
||||
}
|
||||
|
||||
get preferredColorScheme() {
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
return COLOR_SCHEME_PREFERENCE.DARK;
|
||||
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
||||
return COLOR_SCHEME_PREFERENCE.LIGHT;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
replaceStylesheet(newPath) {
|
||||
const head = document.querySelector("head");
|
||||
// remove default theme
|
||||
|
|
|
@ -64,11 +64,9 @@ export class ThemeLoader {
|
|||
return theme;
|
||||
}
|
||||
// return default theme
|
||||
const preference = this._platform.preferredColorScheme;
|
||||
switch (preference) {
|
||||
case COLOR_SCHEME_PREFERENCE.DARK:
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
return this._platform.config["defaultTheme"].dark;
|
||||
case COLOR_SCHEME_PREFERENCE.LIGHT:
|
||||
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
||||
return this._platform.config["defaultTheme"].light;
|
||||
}
|
||||
return undefined;
|
||||
|
|
Loading…
Reference in a new issue