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', type: 'string',
required: false, 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( export const INSTANCE_DEFAULT_CONFIG = convertDefinitions(
INSTANCE_DEFAULT_CONFIG_DEFINITIONS, INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
@ -672,6 +684,11 @@ export const SYNC_DEFAULT_CONFIG_DEFINITIONS = {
description: 'Collapse navigation panel to header only', description: 'Collapse navigation panel to header only',
default: false, default: false,
}, },
muteFilters: {
description: 'Object containing mute filters',
type: 'object',
default: {},
}
} }
export const SYNC_DEFAULT_CONFIG = convertDefinitions( export const SYNC_DEFAULT_CONFIG = convertDefinitions(
SYNC_DEFAULT_CONFIG_DEFINITIONS, SYNC_DEFAULT_CONFIG_DEFINITIONS,
@ -740,14 +757,27 @@ export const ROOT_CONFIG_DEFINITIONS = {
export const validateSetting = ({ export const validateSetting = ({
value, value,
path, path: fullPath,
definition, definition,
throwError, throwError,
defaultState, defaultState,
validateObjects = true,
}) => { }) => {
if (value === undefined) return // only null is allowed as missing value const path = fullPath.replace(/^simple./, '')
if (get(defaultState, path) === undefined) { if (validateObjects && definition.type === 'object' && path.split('.').length <= 1) {
const string = `Unknown option ${path}, value: ${value}` 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) { if (throwError) {
throw new Error(string) throw new Error(string)

View file

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

View file

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