fix objects not loading/saved/verified

This commit is contained in:
Henry Jameson 2026-04-10 01:08:24 +03:00
commit 14e2e57c55
3 changed files with 41 additions and 12 deletions

View file

@ -531,6 +531,18 @@ export const INSTANCE_DEFAULT_CONFIG_DEFINITIONS = {
type: 'string',
required: false,
},
theme3hacks: {
description: 'Theme 3 hacks (need separation)',
type: 'object',
required: false,
default: {},
},
highlights: {
description: 'User highlights',
type: 'object',
required: false,
default: {},
},
}
export const INSTANCE_DEFAULT_CONFIG = convertDefinitions(
INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
@ -672,6 +684,11 @@ export const SYNC_DEFAULT_CONFIG_DEFINITIONS = {
description: 'Collapse navigation panel to header only',
default: false,
},
muteFilters: {
description: 'Object containing mute filters',
type: 'object',
default: {},
}
}
export const SYNC_DEFAULT_CONFIG = convertDefinitions(
SYNC_DEFAULT_CONFIG_DEFINITIONS,
@ -740,14 +757,27 @@ export const ROOT_CONFIG_DEFINITIONS = {
export const validateSetting = ({
value,
path,
path: fullPath,
definition,
throwError,
defaultState,
validateObjects = true,
}) => {
if (value === undefined) return // only null is allowed as missing value
if (get(defaultState, path) === undefined) {
const string = `Unknown option ${path}, value: ${value}`
const path = fullPath.replace(/^simple./, '')
if (validateObjects && definition.type === 'object' && path.split('.').length <= 1) {
console.error(`attempt to set object ${fullPath} instead of its children. ignoring.`)
return undefined
}
if (path.includes('muteFilters')) {
console.log('##', path, value, definition)
console.log(value)
console.log(path)
console.log('====')
}
if (value === undefined) return undefined // only null is allowed as missing value
if (get(defaultState, path.split('.')[0]) === undefined) {
const string = `Unknown option ${fullPath}, value: ${value}`
if (throwError) {
throw new Error(string)

View file

@ -201,6 +201,7 @@ export const useInstanceStore = defineStore('instance', {
definition,
throwError: true,
defaultState: DEFAULT_STATE,
validateObjects: false,
})
set(this, path, finalValue)

View file

@ -302,7 +302,7 @@ export const _mergePrefs = (recent, stale) => {
: ROOT_CONFIG_DEFINITIONS[entry]
const finalValue = validateSetting({
path: entry,
path,
value: args[0],
definition,
throwError: false,
@ -516,7 +516,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
: ROOT_CONFIG_DEFINITIONS[path.split('.')[1]]
const finalValue = validateSetting({
path: path.split('.')[1],
path,
value,
definition,
throwError: false,
@ -777,21 +777,19 @@ export const useSyncConfigStore = defineStore('sync_config', {
afterLoad(state) {
console.debug('Validating persisted state of SyncConfig')
const newState = { ...state }
const newEntries = Object.entries(newState.prefsStorage.simple).map(
const newEntries = Object.entries(ROOT_CONFIG).map(
([path, value]) => {
if (path === 'muteFilters') {
return value
}
const definition = ROOT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path,
value,
value: newState.prefsStorage.simple[path],
definition,
throwError: false,
validateObjects: false,
defaultState: ROOT_CONFIG,
})
return finalValue === undefined ? undefined : [path, finalValue]
return finalValue === undefined ? definition.default : [path, finalValue]
},
)
newState.prefsStorage.simple = Object.fromEntries(