From 9336140486f50159b935001b7ebadf3d9bda89ec Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 22 Jan 2020 00:37:19 +0200 Subject: massively improved initial theme loading code, added checks and warnings when loading theme files (import/localStorage/defaults) --- src/modules/instance.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/modules/instance.js') diff --git a/src/modules/instance.js b/src/modules/instance.js index 625323b9..8781646d 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -1,5 +1,5 @@ import { set } from 'vue' -import { setPreset } from '../services/style_setter/style_setter.js' +import { getPreset, applyTheme } from '../services/style_setter/style_setter.js' import { instanceDefaultProperties } from './config.js' const defaultState = { @@ -10,6 +10,7 @@ const defaultState = { textlimit: 5000, server: 'http://localhost:4040/', theme: 'pleroma-dark', + themeData: undefined, background: '/static/aurora_borealis.jpg', logo: '/static/logo.png', logoMask: true, @@ -96,6 +97,9 @@ const instance = { dispatch('initializeSocket') } break + case 'theme': + dispatch('setTheme', value) + break } }, async getStaticEmoji ({ commit }) { @@ -147,9 +151,16 @@ const instance = { } }, - setTheme ({ commit }, themeName) { + setTheme ({ commit, rootState }, themeName) { commit('setInstanceOption', { name: 'theme', value: themeName }) - return setPreset(themeName, commit) + getPreset(themeName) + .then(themeData => { + commit('setInstanceOption', { name: 'themeData', value: themeData }) + // No need to apply theme if there's user theme already + const { customTheme } = rootState.config + if (customTheme) return + applyTheme(themeData.theme) + }) }, fetchEmoji ({ dispatch, state }) { if (!state.customEmojiFetched) { -- cgit v1.2.3-70-g09d2 From 5b7acca0bab12e88ad5b2c80b120859e440133de Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Sat, 22 Feb 2020 10:57:08 +0200 Subject: make theme loading work with source-only presets --- src/modules/instance.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/modules/instance.js') diff --git a/src/modules/instance.js b/src/modules/instance.js index 8781646d..f96337e4 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -1,5 +1,6 @@ import { set } from 'vue' import { getPreset, applyTheme } from '../services/style_setter/style_setter.js' +import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' import { instanceDefaultProperties } from './config.js' const defaultState = { @@ -159,7 +160,14 @@ const instance = { // No need to apply theme if there's user theme already const { customTheme } = rootState.config if (customTheme) return - applyTheme(themeData.theme) + + // New theme presets don't have 'theme' property, they use 'source' + const themeSource = themeData.source + if (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION) { + applyTheme(themeSource) + } else { + applyTheme(themeData.theme) + } }) }, fetchEmoji ({ dispatch, state }) { -- cgit v1.2.3-70-g09d2 From ee582855d2f6ea02d8ee3cc4536b0b71ccece920 Mon Sep 17 00:00:00 2001 From: Shpuld Shpludson Date: Fri, 28 Feb 2020 17:20:40 +0000 Subject: Apply suggestion to src/modules/instance.js --- src/modules/instance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/instance.js') diff --git a/src/modules/instance.js b/src/modules/instance.js index f96337e4..ffece311 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -163,7 +163,7 @@ const instance = { // New theme presets don't have 'theme' property, they use 'source' const themeSource = themeData.source - if (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION) { + if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) { applyTheme(themeSource) } else { applyTheme(themeData.theme) -- cgit v1.2.3-70-g09d2