Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
18 KB
Referenced Files
None
Subscribers
None
diff --git a/src/stores/default_state/default_config_state.js b/src/stores/default_state/default_config_state.js
index 24aabb74b9..47d77595f9 100644
--- a/src/stores/default_state/default_config_state.js
+++ b/src/stores/default_state/default_config_state.js
@@ -14,21 +14,6 @@ export const convertDefinitions = (definitions) =>
/// Put settings here only if it does not make sense for a normal user
/// to override it.
export const INSTANCE_IDENTITY_DEFAULT_DEFINITIONS = {
- style: {
- description: 'Instance default style name',
- type: 'string',
- required: false,
- },
- palette: {
- description: 'Instance default palette name',
- type: 'string',
- required: false,
- },
- theme: {
- description: 'Instance default theme name',
- type: 'string',
- required: false,
- },
defaultAvatar: {
description: "Default avatar image to use when user doesn't have one set",
type: 'string',
@@ -136,6 +121,42 @@ export const INSTANCE_DEFAULT_CONFIG_DEFINITIONS = {
type: 'number', // not a boolean so we could potentially make multiple levels of expert-ness
default: 0,
},
+ theme: {
+ description: 'Very old theme store, stores preset name, still in use',
+ default: null,
+ },
+ colors: {
+ description:
+ 'VERY old theme store, just colors of V1, probably not even used anymore',
+ default: {},
+ },
+ // V2
+ customTheme: {
+ description:
+ '"Snapshot", previously was used as actual theme store for V2 so it\'s still used in case of PleromaFE downgrade event.',
+ default: null,
+ },
+ customThemeSource: {
+ description: '"Source", stores original theme data',
+ default: null,
+ },
+ // V3
+ style: {
+ description: 'Style name for builtins',
+ default: null,
+ },
+ styleCustomData: {
+ description: 'Custom style data (i.e. not builtin)',
+ default: null,
+ },
+ palette: {
+ description: 'Palette name for builtins',
+ default: null,
+ },
+ paletteCustomData: {
+ description: 'Custom palette data (i.e. not builtin)',
+ default: null,
+ },
hideISP: {
description: 'Hide Instance-specific panel',
default: false,
@@ -945,46 +966,6 @@ export const SYNC_DEFAULT_CONFIG = convertDefinitions(
)
export const SYNC_ONLY_KEYS = new Set(Object.keys(SYNC_DEFAULT_CONFIG))
-export const THEME_CONFIG_DEFINITIONS = {
- theme: {
- description: 'Very old theme store, stores preset name, still in use',
- default: null,
- },
- colors: {
- description:
- 'VERY old theme store, just colors of V1, probably not even used anymore',
- default: {},
- },
- // V2
- customTheme: {
- description:
- '"Snapshot", previously was used as actual theme store for V2 so it\'s still used in case of PleromaFE downgrade event.',
- default: null,
- },
- customThemeSource: {
- description: '"Source", stores original theme data',
- default: null,
- },
- // V3
- style: {
- description: 'Style name for builtins',
- default: null,
- },
- styleCustomData: {
- description: 'Custom style data (i.e. not builtin)',
- default: null,
- },
- palette: {
- description: 'Palette name for builtins',
- default: null,
- },
- paletteCustomData: {
- description: 'Custom palette data (i.e. not builtin)',
- default: null,
- },
-}
-export const THEME_CONFIG = convertDefinitions(THEME_CONFIG_DEFINITIONS)
-
export const makeUndefined = (c) =>
Object.fromEntries(Object.keys(c).map((key) => [key, undefined]))
@@ -995,14 +976,12 @@ export const ROOT_CONFIG = {
...INSTANCE_DEFAULT_CONFIG,
...LOCAL_DEFAULT_CONFIG,
...SYNC_DEFAULT_CONFIG,
- ...THEME_CONFIG,
}
export const ROOT_CONFIG_DEFINITIONS = {
...INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
...LOCAL_DEFAULT_CONFIG_DEFINITIONS,
...SYNC_DEFAULT_CONFIG_DEFINITIONS,
- ...THEME_CONFIG_DEFINITIONS,
}
const maybeThrow = (doThrow, error, fallback) => {
diff --git a/src/stores/interface.js b/src/stores/interface.js
index e3994f4150..206fdf6b3b 100644
--- a/src/stores/interface.js
+++ b/src/stores/interface.js
@@ -1,5 +1,6 @@
import { cloneDeep, set, unset } from 'lodash-es'
import { defineStore } from 'pinia'
+import sum from 'hash-sum'
import {
applyTheme,
@@ -333,7 +334,7 @@ export const useInterfaceStore = defineStore('interface', {
setPrefersDarkMode(value) {
if (this.prefersDark !== value) {
this.prefersDark = value
- this.applyTheme()
+ this.applyTheme(null, true)
}
},
setFontsList(value) {
@@ -434,16 +435,22 @@ export const useInterfaceStore = defineStore('interface', {
return {}
}
},
- setPalette(value, store) {
+ async setPalette(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3Palette(store)
this.resetThemeV2(store)
this.setPreference({ path: 'palette', value, store })
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
- this.applyTheme({ recompile: true, store })
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
+
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
- setPaletteCustom(value, store) {
+ async setPaletteCustom(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3Palette(store)
this.resetThemeV2(store)
@@ -452,9 +459,13 @@ export const useInterfaceStore = defineStore('interface', {
value,
store,
})
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
+
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
- this.applyTheme({ recompile: true, store })
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
async fetchStylesIndex() {
try {
@@ -473,17 +484,23 @@ export const useInterfaceStore = defineStore('interface', {
return {}
}
},
- setStyle(value, store) {
+ async setStyle(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3(store)
this.resetThemeV2(store)
this.resetThemeV3Palette(store)
this.setPreference({ path: 'style', value, store })
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
+
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
- this.applyTheme({ recompile: true, store })
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
- setStyleCustom(value, store) {
+ async setStyleCustom(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3(store)
this.resetThemeV2(store)
this.resetThemeV3Palette(store)
@@ -493,9 +510,13 @@ export const useInterfaceStore = defineStore('interface', {
value,
store,
})
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
- this.applyTheme({ recompile: true, store })
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
+
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
async fetchThemesIndex() {
try {
@@ -511,17 +532,23 @@ export const useInterfaceStore = defineStore('interface', {
return {}
}
},
- setTheme(value, store) {
+ async setTheme(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3(store)
this.resetThemeV3Palette(store)
this.resetThemeV2(store)
this.setPreference({ path: 'theme', value, store })
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
+
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
- this.applyTheme({ recompile: true, store })
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
- setThemeCustom(value, store) {
+ async setThemeCustom(value, store) {
+ const { fullIdentifier: themeIdentifierOld } = this.getUsedThemeInfo()
this.resetThemeV3(store)
this.resetThemeV3Palette(store)
this.resetThemeV2(store)
@@ -531,9 +558,12 @@ export const useInterfaceStore = defineStore('interface', {
path: 'customThemeSource',
value,
})
- this.pushPreferences({ store })
+ await this.pushPreferences({ store })
+ const { fullIdentifier: themeIdentifierNew } = this.getUsedThemeInfo()
- this.applyTheme({ recompile: true, store })
+ if (themeIdentifierNew !== themeIdentifierOld) {
+ this.applyTheme(store, true)
+ }
},
resetThemeV3(store) {
this.unsetPreference({ path: 'style', store })
@@ -563,6 +593,114 @@ export const useInterfaceStore = defineStore('interface', {
store,
})
},
+ getUsedThemeInfo() {
+ let {
+ theme: instanceThemeV2Name,
+ customTheme: instanceThemeV2Snapshot,
+ customThemeSource: instanceThemeV2Source,
+ style: instanceStyleName,
+ styleCustomData: instanceStyleCustomData,
+ palette: instancePaletteName,
+ paletteCustomData: instancePaletteCustomData,
+ } = useMergedConfigStore().mergedConfigDefault
+
+ let {
+ theme: userThemeV2Name,
+ customTheme: userThemeV2Snapshot,
+ customThemeSource: userThemeV2Source,
+ style: userStyleName,
+ styleCustomData: userStyleCustomData,
+ palette: userPaletteName,
+ paletteCustomData: userPaletteCustomData,
+ } = useMergedConfigStore().mergedConfigWithoutDefaults
+
+ console.debug(
+ `User V3 palette: ${userPaletteName}, style: ${userStyleName}, custom: ${!!userStyleCustomData}`,
+ )
+ console.debug(
+ `User V2 name: ${userThemeV2Name}, source: ${!!userThemeV2Source}, snapshot: ${!!userThemeV2Snapshot}`,
+ )
+
+ console.debug(
+ `Instance V3 palette: ${instancePaletteName}, style: ${instanceStyleName}, custom: ${!!instanceStyleCustomData}`,
+ )
+ console.debug(
+ `Instance V2 name: ${instanceThemeV2Name}, custom: ${!!instanceThemeV2Snapshot}`,
+ )
+
+ const userThemeV2Used = Boolean(userThemeV2Name || userThemeV2Source || userThemeV2Snapshot)
+ const userThemeV3Used = Boolean(userStyleName || userStyleCustomData)
+ const userThemeUsed = userThemeV2Used || userThemeV3Used
+
+ const instanceThemeV2Used = Boolean(instanceThemeV2Name || instanceThemeV2Source || instanceThemeV2Snapshot)
+ const instanceThemeV3Used = Boolean(instanceStyleName || instanceStyleCustomData)
+ const instanceThemeUsed = instanceThemeV2Used || instanceThemeV3Used
+
+ const userPaletteUsed = Boolean(userPaletteName || userPaletteCustomData)
+ const instancePaletteUsed = Boolean(instancePaletteName || instancePaletteCustomData)
+
+ if (userStyleName === 'stock') userStyleName = undefined
+ if (instanceStyleName === 'stock') instanceStyleName = undefined
+ if (userPaletteName === 'auto') userPaletteName = undefined
+ if (instancePaletteName === 'auto') instancePaletteName = undefined
+
+ const majorVersionUsed = (() => {
+ if (userThemeUsed) {
+ return userThemeV2Used ? 'v2' : 'v3'
+ } else {
+ return instanceThemeV2Used ? 'v2' : 'v3'
+ }
+ })()
+
+ const themeCustomData = (() => {
+ if (userThemeUsed) {
+ return userThemeV2Used ? userThemeV2Source ?? userThemeV2Snapshot : userStyleCustomData
+ } else {
+ return instanceThemeV2Used ? instanceThemeV2Source ?? instanceThemeV2Snapshot : instanceStyleCustomData
+ }
+ })()
+ const paletteCustomData = userPaletteUsed
+ ? userPaletteCustomData
+ : instancePaletteCustomData
+
+ const themeName = (() => {
+ if (userThemeUsed) {
+ return userThemeV2Used ? userThemeV2Name : userStyleName
+ } else {
+ return instanceThemeV2Used ? instanceThemeV2Name : instanceStyleName
+ }
+ })()
+ const paletteName = userPaletteUsed
+ ? userPaletteName
+ : instancePaletteName
+
+ const themeIdentifier = (() => {
+ if (themeCustomData) {
+ return `<custom: ${sum(themeCustomData)}>`
+ } else {
+ return themeName
+ }
+ })()
+ const paletteIdentifier = (() => {
+ if (majorVersionUsed === 'v2') return 'none'
+ if (userPaletteUsed) {
+ return `<custom: ${sum(paletteCustomData)}>`
+ } else {
+ return paletteName
+ }
+ })()
+ const fullIdentifier = `${majorVersionUsed}:${themeIdentifier}:${paletteIdentifier}`
+
+ console.debug(`Final identifier: ${fullIdentifier}`)
+ return {
+ fullIdentifier,
+ majorVersionUsed,
+ themeName,
+ themeCustomData,
+ paletteName,
+ paletteCustomData,
+ }
+ },
async getThemeData() {
const getData = async (resource, index, customData, name) => {
const capitalizedResource =
@@ -603,67 +741,13 @@ export const useInterfaceStore = defineStore('interface', {
return result
}
- let {
- theme: instanceThemeName,
- style: instanceStyleName,
- palette: instancePaletteName,
- } = useInstanceStore().instanceIdentity
-
const {
- style: userStyleName,
- styleCustomData: userStyleCustomData,
- palette: userPaletteName,
- paletteCustomData: userPaletteCustomData,
- } = useMergedConfigStore().mergedConfig
-
- let {
- theme: userThemeV2Name,
- customTheme: userThemeV2Snapshot,
- customThemeSource: userThemeV2Source,
- } = useMergedConfigStore().mergedConfig
-
- let majorVersionUsed
-
- console.debug(
- `User V3 palette: ${userPaletteName}, style: ${userStyleName} , custom: ${!!userStyleCustomData}`,
- )
- console.debug(
- `User V2 name: ${userThemeV2Name}, source: ${!!userThemeV2Source}, snapshot: ${!!userThemeV2Snapshot}`,
- )
-
- console.debug(
- `Instance V3 palette: ${instancePaletteName}, style: ${instanceStyleName}`,
- )
- console.debug('Instance V2 theme: ' + instanceThemeName)
-
- if (
- userPaletteName ||
- userPaletteCustomData ||
- userStyleName ||
- userStyleCustomData ||
- // User V2 overrides instance V3
- ((instancePaletteName || instanceStyleName) &&
- instanceThemeName == null &&
- userThemeV2Name == null)
- ) {
- // Palette and/or style overrides V2 themes
- instanceThemeName = null
- userThemeV2Name = null
- userThemeV2Source = null
- userThemeV2Snapshot = null
-
- majorVersionUsed = 'v3'
- } else if (
- userThemeV2Name ||
- userThemeV2Snapshot ||
- userThemeV2Source ||
- instanceThemeName
- ) {
- majorVersionUsed = 'v2'
- } else {
- // if all fails fallback to v3
- majorVersionUsed = 'v3'
- }
+ majorVersionUsed,
+ themeName,
+ themeCustomData,
+ paletteName,
+ paletteCustomData,
+ } = this.getUsedThemeInfo()
if (majorVersionUsed === 'v3') {
await Promise.all([
@@ -686,8 +770,8 @@ export const useInterfaceStore = defineStore('interface', {
const style = await getData(
'style',
useInstanceStore().stylesIndex,
- userStyleCustomData,
- userStyleName || instanceStyleName,
+ themeCustomData,
+ themeName,
)
this.styleNameUsed = style.nameUsed
this.styleDataUsed = style.dataUsed
@@ -714,16 +798,15 @@ export const useInterfaceStore = defineStore('interface', {
const defaultPalette = (() => {
if (this.prefersDark === null) return null
const matchRegex = this.prefersDark ? /dark/i : /light/i
- return Object.keys(allPalettes).find((x) => matchRegex.test(x))
- })() ?? allPalettes[0]
+ const keys = Object.keys(allPalettes)
+ return keys.find((x) => matchRegex.test(x)) ?? keys[0]
+ })()
const palette = await getData(
'palette',
allPalettes,
- userPaletteCustomData,
- (userPaletteName === 'auto' || userPaletteName === undefined)
- ? defaultPalette
- : userPaletteName,
+ paletteCustomData,
+ paletteName ?? defaultPalette,
)
this.paletteNameUsed = palette.nameUsed
@@ -771,7 +854,7 @@ export const useInterfaceStore = defineStore('interface', {
'theme',
useInstanceStore().themesIndex,
userThemeV2Source || userThemeV2Snapshot,
- userThemeV2Name || instanceThemeName,
+ userThemeV2Name || instanceThemeV2Name,
)
this.themeNameUsed = theme.nameUsed
this.themeDataUsed = theme.dataUsed
@@ -780,7 +863,7 @@ export const useInterfaceStore = defineStore('interface', {
async setThemeApplied() {
this.themeApplied = true
},
- async applyTheme({ recompile = false, store } = {}) {
+ async applyTheme(store, recompile) {
const { mergedConfig } = useMergedConfigStore()
const { forceThemeRecompilation, themeDebug } = mergedConfig
diff --git a/src/stores/local_config.js b/src/stores/local_config.js
index 3f4d6258ed..165a144735 100644
--- a/src/stores/local_config.js
+++ b/src/stores/local_config.js
@@ -2,8 +2,6 @@ import { cloneDeep, set, unset } from 'lodash-es'
import { defineStore } from 'pinia'
import {
- THEME_CONFIG,
- THEME_CONFIG_DEFINITIONS,
INSTANCE_DEFAULT_CONFIG,
INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
LOCAL_DEFAULT_CONFIG,
@@ -25,8 +23,7 @@ export const useLocalConfigStore = defineStore('local_config', {
set({ path, value }) {
const definition =
LOCAL_DEFAULT_CONFIG_DEFINITIONS[path] ??
- INSTANCE_DEFAULT_CONFIG_DEFINITIONS[path] ??
- THEME_CONFIG_DEFINITIONS[path]
+ INSTANCE_DEFAULT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path,
@@ -36,7 +33,6 @@ export const useLocalConfigStore = defineStore('local_config', {
defaultState: {
...INSTANCE_DEFAULT_CONFIG,
...LOCAL_DEFAULT_CONFIG,
- ...THEME_CONFIG,
},
})

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 8:25 AM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1841062
Default Alt Text
(18 KB)

Event Timeline