From cb3dafa55b7c6269dc65f021a1324312c128f14e Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Aug 2022 04:51:40 +0530 Subject: [PATCH] Fix vuetify dark mode initialization logic --- src/plugins/vuetify.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index fd45c4f..2071990 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -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: {