diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index 30ec282..fd45c4f 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -1,6 +1,9 @@ import Vue from 'vue' import Vuetify from 'vuetify/lib/framework' +import { isString } from 'lodash-es' +import { COLOR_SCHEME_STATES } from '@/store/prefs-store' + Vue.use(Vuetify) export default new Vuetify({ @@ -9,7 +12,25 @@ 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: false, + dark: (() => { + // Partly duplicated in App.vue + try { + const LSValue = window.localStorage.getItem('COLOR_SCHEME') + if (isString(LSValue) && LSValue.length !== 0) { + const state = JSON.parse(LSValue) + switch (state) { + case COLOR_SCHEME_STATES.SYSTEM: + return window.matchMedia('(prefers-color-scheme: dark)').matches + case COLOR_SCHEME_STATES.DARK: + return true + case COLOR_SCHEME_STATES.LIGHT: + return false + } + } + } catch (e) { + return false + } + })(), themes: { light: { primary: '#455A64',