Fix vuetify dark mode initialization logic

This commit is contained in:
root
2022-08-26 04:51:40 +05:30
parent f9a4b313dc
commit cb3dafa55b
+7 -2
View File
@@ -13,6 +13,8 @@ export default new Vuetify({
theme: {
// There's apparently a race condition that causes components being rendered shortly before dark mode initialization unable to change to dark mode
dark: (() => {
const autoValue = window.matchMedia('(prefers-color-scheme: dark)').matches
// Partly duplicated in App.vue
try {
const LSValue = window.localStorage.getItem('COLOR_SCHEME')
@@ -20,15 +22,18 @@ export default new Vuetify({
const state = JSON.parse(LSValue)
switch (state) {
case COLOR_SCHEME_STATES.SYSTEM:
return window.matchMedia('(prefers-color-scheme: dark)').matches
return autoValue
case COLOR_SCHEME_STATES.DARK:
return true
case COLOR_SCHEME_STATES.LIGHT:
return false
}
} else {
return autoValue
}
} catch (e) {
return false
// Auto by default
return autoValue
}
})(),
themes: {