feat: default to light mode if the browser prefers light mode
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
d5b2b43bf5
commit
3866ced880
1 changed files with 18 additions and 2 deletions
|
@ -6,8 +6,16 @@ export default function loadPreferredThemes() {
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
const baseURL = runtimeConfig.app.baseURL;
|
const baseURL = runtimeConfig.app.baseURL;
|
||||||
|
|
||||||
const currentStyle = settingsLoad().selectedThemeStyle ?? `${baseURL}themes/style/dark.css`
|
let currentStyle = settingsLoad().selectedThemeStyle ?? undefined
|
||||||
const currentLayout = settingsLoad().selectedThemeLayout ?? `${baseURL}themes/layout/gorb.css`
|
let currentLayout = settingsLoad().selectedThemeLayout ?? `${baseURL}themes/layout/gorb.css`
|
||||||
|
|
||||||
|
if (!currentStyle) {
|
||||||
|
if (prefersLight()) {
|
||||||
|
currentStyle = `${baseURL}themes/style/light.css`
|
||||||
|
} else {
|
||||||
|
currentStyle = `${baseURL}themes/style/dark.css`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (styleLinkElement) {
|
if (styleLinkElement) {
|
||||||
styleLinkElement.href = currentStyle;
|
styleLinkElement.href = currentStyle;
|
||||||
|
@ -34,3 +42,11 @@ function createStyleHead(id: string, themeUrl: string) {
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prefersLight(): boolean {
|
||||||
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue