From d2683a672859cb0fb46037540f62f4fdb07407c1 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 17 Jul 2024 22:10:11 +0300 Subject: new theme selector, RC --- src/modules/interface.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/modules/interface.js') diff --git a/src/modules/interface.js b/src/modules/interface.js index a0746052..b56b60ec 100644 --- a/src/modules/interface.js +++ b/src/modules/interface.js @@ -212,12 +212,13 @@ const interfaceMod = { setLastTimeline ({ commit }, value) { commit('setLastTimeline', value) }, - setTheme ({ commit, rootState }, { themeName, themeData, recompile } = {}) { + setTheme ({ commit, rootState }, { themeName, themeData, recompile, saveData } = {}) { const { theme: instanceThemeName } = rootState.instance const { + theme: userThemeName, customTheme: userThemeSnapshot, customThemeSource: userThemeSource, forceThemeRecompilation, @@ -225,6 +226,8 @@ const interfaceMod = { theme3hacks } = rootState.config + const actualThemeName = userThemeName || instanceThemeName + const forceRecompile = forceThemeRecompilation || recompile // If we're not not forced to recompile try using @@ -236,28 +239,31 @@ const interfaceMod = { let promise = null - if (themeName) { - promise = getPreset(themeName) - .then(themeData => { - return normalizeThemeData(themeData) - }) - } else if (themeData) { + 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)) + } else if (themeName) { + promise = getPreset(themeName).then(themeData => 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 (actualThemeName && actualThemeName !== 'custom') { + promise = getPreset(actualThemeName).then(themeData => normalizeThemeData(themeData)) + } else { + throw new Error('Cannot load any theme!') } promise .then(realThemeData => { const theme2ruleset = convertTheme2To3(realThemeData) + + if (saveData) { + commit('setOption', { name: 'theme', value: themeName || actualThemeName }) + commit('setOption', { name: 'customTheme', value: realThemeData }) + commit('setOption', { name: 'customThemeSource', value: realThemeData }) + } const hacks = [] Object.entries(theme3hacks).forEach(([key, value]) => { -- cgit v1.2.3-70-g09d2