commit: 115335e98a675aa9caff747053ea23820ff8e27a
parent 41f8c3dad59e6513b53f29964e10e7a3a4440cf0
Author: Henry Jameson <me@hjkos.com>
Date: Fri, 12 Jul 2024 02:13:08 +0300
move theme application to interface module
Diffstat:
2 files changed, 82 insertions(+), 85 deletions(-)
diff --git a/src/modules/instance.js b/src/modules/instance.js
@@ -1,6 +1,3 @@
-import { getPreset, applyTheme, tryLoadCache } from '../services/style_setter/style_setter.js'
-import { CURRENT_VERSION, generatePreset } from 'src/services/theme_data/theme_data.service.js'
-import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
import apiService from '../services/api/api.service.js'
import { instanceDefaultProperties } from './config.js'
import { langCodeToCldrName, ensureFinalFallback } from '../i18n/languages.js'
@@ -375,88 +372,6 @@ const instance = {
console.warn(e)
}
},
-
- setTheme ({ commit, state, rootState }, { themeName, themeData, recompile } = {}) {
- // const {
- // themeApplied
- // } = rootState.interface
- const {
- theme: instanceThemeName
- } = state
-
- const {
- customTheme: userThemeSnapshot,
- customThemeSource: userThemeSource,
- forceThemeRecompilation,
- themeDebug
- } = rootState.config
-
- const forceRecompile = forceThemeRecompilation || recompile
-
- // If we're not not forced to recompile try using
- // cache (tryLoadCache return true if load successful)
- if (!forceRecompile && !themeDebug && tryLoadCache()) {
- commit('setThemeApplied')
- }
-
- const normalizeThemeData = (themeData) => {
- console.log('NORMAL', themeData)
- if (themeData.themeFileVerison === 1) {
- return generatePreset(themeData).theme
- }
- // New theme presets don't have 'theme' property, they use 'source'
- const themeSource = themeData.source
-
- let out // shout, shout let it all out
- if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) {
- out = themeSource || themeData
- } else {
- out = themeData.theme
- }
-
- // generatePreset here basically creates/updates "snapshot",
- // while also fixing the 2.2 -> 2.3 colors/shadows/etc
- return generatePreset(out).theme
- }
-
- let promise = null
-
- if (themeName) {
- // commit('setInstanceOption', { name: 'theme', value: themeName })
- promise = getPreset(themeName)
- .then(themeData => {
- // commit('setInstanceOption', { name: 'themeData', value: themeData })
- return normalizeThemeData(themeData)
- })
- } else if (themeData) {
- promise = Promise.resolve(normalizeThemeData(themeData))
- } else {
- if (userThemeSource || userThemeSnapshot) {
- if (userThemeSource && userThemeSource.themeEngineVersion === CURRENT_VERSION) {
- promise = Promise.resolve(normalizeThemeData(userThemeSource))
- } else {
- promise = Promise.resolve(normalizeThemeData(userThemeSnapshot))
- }
- } else if (instanceThemeName) {
- promise = getPreset(themeName).then(themeData => normalizeThemeData(themeData))
- }
- }
-
- promise
- .then(realThemeData => {
- console.log('FR FR 1', realThemeData)
- const ruleset = convertTheme2To3(realThemeData)
- console.log('FR FR 2', ruleset)
-
- applyTheme(
- ruleset,
- () => commit('setThemeApplied'),
- themeDebug
- )
- })
-
- return promise
- },
fetchEmoji ({ dispatch, state }) {
if (!state.customEmojiFetched) {
state.customEmojiFetched = true
diff --git a/src/modules/interface.js b/src/modules/interface.js
@@ -1,3 +1,7 @@
+import { getPreset, applyTheme, tryLoadCache } from '../services/style_setter/style_setter.js'
+import { CURRENT_VERSION, generatePreset } from 'src/services/theme_data/theme_data.service.js'
+import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
+
const defaultState = {
localFonts: null,
themeApplied: false,
@@ -207,6 +211,84 @@ const interfaceMod = {
},
setLastTimeline ({ commit }, value) {
commit('setLastTimeline', value)
+ },
+ setTheme ({ commit, rootState }, { themeName, themeData, recompile } = {}) {
+ // const {
+ // themeApplied
+ // } = rootState.interface
+ const {
+ theme: instanceThemeName
+ } = rootState.instance
+
+ const {
+ customTheme: userThemeSnapshot,
+ customThemeSource: userThemeSource,
+ forceThemeRecompilation,
+ themeDebug
+ } = rootState.config
+
+ const forceRecompile = forceThemeRecompilation || recompile
+
+ // If we're not not forced to recompile try using
+ // cache (tryLoadCache return true if load successful)
+ if (!forceRecompile && !themeDebug && tryLoadCache()) {
+ commit('setThemeApplied')
+ }
+
+ const normalizeThemeData = (themeData) => {
+ if (themeData.themeFileVerison === 1) {
+ return generatePreset(themeData).theme
+ }
+ // New theme presets don't have 'theme' property, they use 'source'
+ const themeSource = themeData.source
+
+ let out // shout, shout let it all out
+ if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) {
+ out = themeSource || themeData
+ } else {
+ out = themeData.theme
+ }
+
+ // generatePreset here basically creates/updates "snapshot",
+ // while also fixing the 2.2 -> 2.3 colors/shadows/etc
+ return generatePreset(out).theme
+ }
+
+ let promise = null
+
+ if (themeName) {
+ // commit('setInstanceOption', { name: 'theme', value: themeName })
+ promise = getPreset(themeName)
+ .then(themeData => {
+ // commit('setInstanceOption', { name: 'themeData', value: themeData })
+ return normalizeThemeData(themeData)
+ })
+ } else if (themeData) {
+ promise = Promise.resolve(normalizeThemeData(themeData))
+ } else {
+ if (userThemeSource || userThemeSnapshot) {
+ if (userThemeSource && userThemeSource.themeEngineVersion === CURRENT_VERSION) {
+ promise = Promise.resolve(normalizeThemeData(userThemeSource))
+ } else {
+ promise = Promise.resolve(normalizeThemeData(userThemeSnapshot))
+ }
+ } else if (instanceThemeName) {
+ promise = getPreset(themeName).then(themeData => normalizeThemeData(themeData))
+ }
+ }
+
+ promise
+ .then(realThemeData => {
+ const ruleset = convertTheme2To3(realThemeData)
+
+ applyTheme(
+ ruleset,
+ () => commit('setThemeApplied'),
+ themeDebug
+ )
+ })
+
+ return promise
}
}
}