From 86585cc64487ced2f97ac022f4416fc6a88751dc Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Nov 2024 23:24:28 +0200 Subject: [PATCH] allow setting palettes from style --- src/boot/after_store.js | 7 ++ .../settings_modal/tabs/appearance_tab.js | 67 ++++++++++++++++--- .../settings_modal/tabs/appearance_tab.scss | 1 + .../settings_modal/tabs/appearance_tab.vue | 23 ++++++- .../tabs/style_tab/style_tab.js | 67 ++++++++++++------- src/i18n/en.json | 4 +- src/modules/interface.js | 8 +-- .../theme_data/theme_data_3.service.js | 4 +- static/palettes/index.json | 8 +-- 9 files changed, 143 insertions(+), 46 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 20a1a591..f88da23a 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -390,6 +390,13 @@ const afterStoreSetup = async ({ store, i18n }) => { app.use(store) app.use(i18n) + // Little thing to get out of invalid theme state + window.resetThemes = () => { + store.dispatch('resetThemeV3') + store.dispatch('resetThemeV3Palette') + store.dispatch('resetThemeV2') + } + app.use(vClickOutside) app.use(VBodyScrollLock) app.use(VueVirtualScroller) diff --git a/src/components/settings_modal/tabs/appearance_tab.js b/src/components/settings_modal/tabs/appearance_tab.js index bba4647c..1e8f596f 100644 --- a/src/components/settings_modal/tabs/appearance_tab.js +++ b/src/components/settings_modal/tabs/appearance_tab.js @@ -33,7 +33,7 @@ const AppearanceTab = { data () { return { availableStyles: [], - availablePalettes: [], + bundledPalettes: [], fileImporter: newImporter({ accept: '.json, .piss', validator: this.importValidator, @@ -41,8 +41,8 @@ const AppearanceTab = { onImportFailure: this.onImportFailure }), palettesKeys: [ - 'background', - 'foreground', + 'bg', + 'fg', 'link', 'text', 'cRed', @@ -103,13 +103,13 @@ const AppearanceTab = { })) }) - updateIndex('palette').then(palettes => { - palettes.forEach(([key, palettePromise]) => palettePromise.then(v => { + updateIndex('palette').then(bundledPalettes => { + bundledPalettes.forEach(([key, palettePromise]) => palettePromise.then(v => { if (Array.isArray(v)) { const [ name, - background, - foreground, + bg, + fg, text, link, cRed = '#FF0000', @@ -117,9 +117,9 @@ const AppearanceTab = { cBlue = '#0000FF', cOrange = '#E3FF00' ] = v - this.availablePalettes.push({ key, name, background, foreground, text, link, cRed, cBlue, cGreen, cOrange }) + this.bundledPalettes.push({ key, name, bg, fg, text, link, cRed, cBlue, cGreen, cOrange }) } else { - this.availablePalettes.push({ key, ...v }) + this.bundledPalettes.push({ key, ...v }) } })) }) @@ -147,6 +147,50 @@ const AppearanceTab = { }) }, computed: { + availablePalettes () { + return [ + ...this.bundledPalettes, + ...this.stylePalettes + ] + }, + stylePalettes () { + if (!this.mergedConfig.styleCustomData) return + const meta = this.mergedConfig.styleCustomData + .find(x => x.component === '@meta') + const result = this.mergedConfig.styleCustomData + .filter(x => x.component.startsWith('@palette')) + .map(x => { + const { + variant, + bg, + fg, + text, + link, + accent, + cRed, + cBlue, + cGreen, + cOrange, + wallpaper + } = x + + const result = { + name: `${meta.name}: ${variant}`, + bg, + fg, + text, + link, + accent, + cRed, + cBlue, + cGreen, + cOrange, + wallpaper + } + return Object.fromEntries(Object.entries(result).filter(([k, v]) => v)) + }) + return result + }, noIntersectionObserver () { return !window.IntersectionObserver }, @@ -253,6 +297,11 @@ const AppearanceTab = { this.$store.dispatch('setPalette', name) this.$store.dispatch('applyTheme') }, + setPaletteCustom (p) { + this.$store.dispatch('resetThemeV2') + this.$store.dispatch('setPaletteCustom', p) + this.$store.dispatch('applyTheme') + }, resetTheming (name) { this.$store.dispatch('resetThemeV2') this.$store.dispatch('resetThemeV3') diff --git a/src/components/settings_modal/tabs/appearance_tab.scss b/src/components/settings_modal/tabs/appearance_tab.scss index b95ef07d..c78b4acc 100644 --- a/src/components/settings_modal/tabs/appearance_tab.scss +++ b/src/components/settings_modal/tabs/appearance_tab.scss @@ -25,6 +25,7 @@ grid-template-columns: 1fr 1fr; grid-gap: 0.5em; + h4, .unsupported-theme-v2 { grid-column: 1 / span 2; } diff --git a/src/components/settings_modal/tabs/appearance_tab.vue b/src/components/settings_modal/tabs/appearance_tab.vue index 32f6f1a7..1b43a690 100644 --- a/src/components/settings_modal/tabs/appearance_tab.vue +++ b/src/components/settings_modal/tabs/appearance_tab.vue @@ -72,8 +72,9 @@

{{ $t('settings.style.themes3.palette.label') }}