From 3fb531976ace7d19f05ba90cf9785a0114f89540 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sat, 9 Feb 2019 11:26:35 +0200 Subject: [PATCH] Change the async stuff to not render app before theme is loaded --- src/boot/after_store.js | 4 +++- src/lib/persisted_state.js | 2 +- src/modules/instance.js | 6 ++++-- src/services/style_setter/style_setter.js | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 5693dcc65a..60cee1bf1e 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -55,7 +55,6 @@ const afterStoreSetup = ({ store, i18n }) => { } copyInstanceOption('nsfwCensorImage') - copyInstanceOption('theme') copyInstanceOption('background') copyInstanceOption('hidePostStats') copyInstanceOption('hideUserStats') @@ -93,6 +92,9 @@ const afterStoreSetup = ({ store, i18n }) => { store.dispatch('initializeSocket') } + return store.dispatch('setTheme', config['theme']) + }) + .then(() => { const router = new VueRouter({ mode: 'history', routes: routes(store), diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index ccd9263343..6f7202cea5 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -48,7 +48,7 @@ export default function createPersistedState ({ return getState(key, storage).then((savedState) => { return store => { try { - if (typeof savedState === 'object') { + if (savedState !== null && typeof savedState === 'object') { // build user cache const usersState = savedState.users || {} usersState.usersObject = {} diff --git a/src/modules/instance.js b/src/modules/instance.js index 4ad418738e..2755e418d4 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -63,9 +63,11 @@ const instance = { case 'name': dispatch('setPageTitle') break - case 'theme': - setPreset(value, commit) } + }, + setTheme ({ commit }, themeName) { + commit('setInstanceOption', { name: 'theme', value: themeName }) + return setPreset(themeName, commit) } } } diff --git a/src/services/style_setter/style_setter.js b/src/services/style_setter/style_setter.js index 10e7ed9b1a..d0b6ccbf3d 100644 --- a/src/services/style_setter/style_setter.js +++ b/src/services/style_setter/style_setter.js @@ -480,7 +480,7 @@ const getThemes = () => { } const setPreset = (val, commit) => { - getThemes().then((themes) => { + return getThemes().then((themes) => { const theme = themes[val] ? themes[val] : themes['pleroma-dark'] const isV1 = Array.isArray(theme) const data = isV1 ? {} : theme.theme