feat: default to light mode if the browser prefers light mode
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
Twig 2025-08-05 03:07:32 +02:00
parent d5b2b43bf5
commit 3866ced880
Signed by: twig
SSH key fingerprint: SHA256:nBO+OwpTkd8LYhe38PIqdxmDvkIg9Vw2EbrRZM97dkU

View file

@ -6,8 +6,16 @@ export default function loadPreferredThemes() {
const runtimeConfig = useRuntimeConfig()
const baseURL = runtimeConfig.app.baseURL;
const currentStyle = settingsLoad().selectedThemeStyle ?? `${baseURL}themes/style/dark.css`
const currentLayout = settingsLoad().selectedThemeLayout ?? `${baseURL}themes/layout/gorb.css`
let currentStyle = settingsLoad().selectedThemeStyle ?? undefined
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) {
styleLinkElement.href = currentStyle;
@ -33,4 +41,12 @@ function createStyleHead(id: string, themeUrl: string) {
href: themeUrl
}]
})
}
function prefersLight(): boolean {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
return true
}
return false
}