mirror of
https://github.com/fmhy/edit.git
synced 2026-01-13 07:21:08 +11:00
fix auto theme switch
This commit is contained in:
parent
c11d628228
commit
2f2aff8614
1 changed files with 10 additions and 5 deletions
|
|
@ -65,10 +65,15 @@ export class ThemeHandler {
|
||||||
|
|
||||||
// Listen for system theme changes (only if user hasn't set a preference)
|
// Listen for system theme changes (only if user hasn't set a preference)
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||||
if (!localStorage.getItem(STORAGE_KEY_MODE)) {
|
setTimeout(() => {
|
||||||
this.state.value.currentMode = e.matches ? 'dark' : 'light'
|
if (!localStorage.getItem(STORAGE_KEY_MODE)) {
|
||||||
this.applyTheme()
|
this.state.value.currentMode = e.matches ? 'dark' : 'light'
|
||||||
}
|
this.applyTheme()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.applyTheme()
|
||||||
|
}
|
||||||
|
}, 10)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,7 +385,7 @@ export function useTheme() {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Ensure theme is applied on mount
|
// Ensure theme is applied on mount
|
||||||
handler.setMode(handler.getMode())
|
handler.applyTheme()
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue