2026-03-24 21:42:22 +02:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
|
|
import { useInstanceStore } from 'src/stores/instance.js'
|
|
|
|
|
import { useLocalConfigStore } from 'src/stores/local_config.js'
|
|
|
|
|
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
LOCAL_ONLY_KEYS,
|
2026-04-05 13:23:53 +03:00
|
|
|
ROOT_CONFIG,
|
2026-03-24 21:42:22 +02:00
|
|
|
} from 'src/modules/default_config_state.js'
|
|
|
|
|
|
|
|
|
|
export const useMergedConfigStore = defineStore('merged_config', {
|
|
|
|
|
getters: {
|
|
|
|
|
mergedConfig: () => {
|
|
|
|
|
const instancePrefs = useInstanceStore().prefsStorage
|
|
|
|
|
const tempPrefs = useLocalConfigStore().tempStorage
|
|
|
|
|
const localPrefs = useLocalConfigStore().prefsStorage
|
|
|
|
|
const syncPrefs = useSyncConfigStore().prefsStorage
|
|
|
|
|
|
2026-03-25 11:41:42 +02:00
|
|
|
const getValue = (k) => {
|
|
|
|
|
if (LOCAL_ONLY_KEYS.has(k)) {
|
|
|
|
|
return tempPrefs[k] ?? localPrefs[k] ?? syncPrefs.simple[k]
|
|
|
|
|
} else {
|
|
|
|
|
return tempPrefs[k] ?? syncPrefs.simple[k]
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-24 21:42:22 +02:00
|
|
|
const getDefault = (k) => instancePrefs[k] ?? ROOT_CONFIG[k]
|
|
|
|
|
|
|
|
|
|
const result = Object.fromEntries(
|
2026-03-25 15:38:31 +02:00
|
|
|
Object.keys(ROOT_CONFIG).map((k) => [k, getValue(k) ?? getDefault(k)]),
|
2026-03-24 21:42:22 +02:00
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
},
|
|
|
|
|
mergedConfigDefault: () => {
|
|
|
|
|
const instancePrefs = useInstanceStore().prefsStorage
|
|
|
|
|
|
|
|
|
|
const getDefault = (k) => instancePrefs[k] ?? ROOT_CONFIG[k]
|
|
|
|
|
|
|
|
|
|
const result = Object.fromEntries(
|
2026-03-25 15:38:31 +02:00
|
|
|
Object.keys(ROOT_CONFIG).map((k) => [k, getDefault(k)]),
|
2026-03-24 21:42:22 +02:00
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
},
|
|
|
|
|
mergedConfigWithoutDefaults: () => {
|
|
|
|
|
const tempPrefs = useLocalConfigStore().tempStorage
|
|
|
|
|
const localPrefs = useLocalConfigStore().prefsStorage
|
|
|
|
|
const syncPrefs = useSyncConfigStore().prefsStorage
|
|
|
|
|
|
|
|
|
|
const getValue = (k) =>
|
2026-04-05 13:17:36 +03:00
|
|
|
tempPrefs[k] ?? localPrefs[k] ?? syncPrefs.simple[k]
|
2026-03-24 21:42:22 +02:00
|
|
|
|
|
|
|
|
const result = Object.fromEntries(
|
2026-04-05 13:17:36 +03:00
|
|
|
Object.keys(ROOT_CONFIG).map((k) => [k, getValue(k)]),
|
2026-03-24 21:42:22 +02:00
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|