Merge branch 'setttingssync' into shigusegubu-themes3

This commit is contained in:
Henry Jameson 2026-03-13 12:44:28 +02:00
commit 756a931ea5
2 changed files with 23 additions and 22 deletions

View file

@ -413,7 +413,7 @@ export const _resetPrefs = (
return totalPrefs return totalPrefs
} }
export const _doMigrations = async (data) => { export const _doMigrations = async (data, setPreference) => {
console.log('TEST', data._version) console.log('TEST', data._version)
if (data._version < VERSION) { if (data._version < VERSION) {
@ -425,7 +425,7 @@ export const _doMigrations = async (data) => {
// Migrate old config to sync config // Migrate old config to sync config
const vuexState = await storage.getItem('vuex-lz') const vuexState = await storage.getItem('vuex-lz')
defaultStateKeys.forEach(key => { defaultStateKeys.forEach(key => {
this.setPreference({ path: `simple.${key}`, value: vuexState.config[key] }) setPreference({ path: `simple.${key}`, value: vuexState.config[key] })
}) })
} }
} }
@ -636,8 +636,8 @@ export const useSyncConfigStore = defineStore('sync_config', {
}) })
} }
recent = recent && await _doMigrations(recent) recent = recent && await _doMigrations(recent, this.setPreference)
stale = stale && await _doMigrations(stale) stale = stale && await _doMigrations(stale, this.setPreference)
if (!needUpload && recent && stale) { if (!needUpload && recent && stale) {
console.debug('Checking if data needs merging...') console.debug('Checking if data needs merging...')

View file

@ -51,7 +51,7 @@ const _wrapData = (data, userName) => {
const _checkValidity = (data) => data._timestamp > 0 const _checkValidity = (data) => data._timestamp > 0
const _verifyPrefs = (state) => { const _verifyHighlights = (state) => {
state.highlight = state.highlight || {} state.highlight = state.highlight || {}
// Simple // Simple
@ -148,7 +148,7 @@ const _mergeJournal = (...journals) => {
) )
} }
export const _mergePrefs = (recent, stale) => { export const _mergeHighlights = (recent, stale) => {
if (!stale) return recent if (!stale) return recent
if (!recent) return stale if (!recent) return stale
const { _journal: recentJournal, ...recentData } = recent const { _journal: recentJournal, ...recentData } = recent
@ -163,8 +163,8 @@ export const _mergePrefs = (recent, stale) => {
* to requested one. Intended only to be used with simple preferences (boolean, number) * to requested one. Intended only to be used with simple preferences (boolean, number)
*/ */
const resultOutput = { ...recentData } const resultOutput = { ...recentData }
const totalJournal = _mergeJournal(staleJournal, recentJournal) const Journal = _mergeJournal(staleJournal, recentJournal)
totalJournal.forEach(({ user, operation, args }) => { Journal.forEach(({ user, operation, args }) => {
if (user.startsWith('_')) { if (user.startsWith('_')) {
throw new Error( throw new Error(
`journal contains entry to edit internal (starts with _) field '${user}', something is incorrect here, ignoring.`, `journal contains entry to edit internal (starts with _) field '${user}', something is incorrect here, ignoring.`,
@ -172,16 +172,16 @@ export const _mergePrefs = (recent, stale) => {
} }
switch (operation) { switch (operation) {
case 'set': case 'set':
resultOutput.highlight[user] = args[0] resultOutput[user] = args[0]
break break
case 'unset': case 'unset':
delete resultOutput.highlight[user] delete resultOutput[user]
break break
default: default:
return console.error(`Unknown journal operation: '${operation}'`) return console.error(`Unknown journal operation: '${operation}'`)
} }
}) })
return { ...resultOutput, _journal: totalJournal } return { ...resultOutput, _journal: Journal }
} }
export const useUserHighlightStore = defineStore('user_highlight', { export const useUserHighlightStore = defineStore('user_highlight', {
@ -272,20 +272,21 @@ export const useUserHighlightStore = defineStore('user_highlight', {
let { recent, stale, needUpload } = _getRecentData(cache, live) let { recent, stale, needUpload } = _getRecentData(cache, live)
const userNew = userData.created_at > NEW_USER_DATE
let dirty = false
const vuexState = await storage.getItem('vuex-lz') const vuexState = await storage.getItem('vuex-lz')
const { highlight } = vuexState.config const { highlight } = vuexState.config
Object.entries(highlight).forEach(([user, value]) => { Object.entries(highlight).forEach(([user, value]) => {
if ((highlight[user]._migrated || 0) < 2) { if ((highlight[user]._migrated || 0) < 1) {
dirty = true
this.set({ user, value: clone(value) }) this.set({ user, value: clone(value) })
// vuexState.config.highlight[user]._migrated = 1 vuexState.config.highlight[user]._migrated = 1
console.log(user, value, this.highlight[user]) console.log(user, value, this.highlight[user])
} }
}) })
storage.setItem('vuex-lz', vuexState) storage.setItem('vuex-lz', vuexState)
const userNew = userData.created_at > NEW_USER_DATE
let dirty = false
if (recent === null) { if (recent === null) {
console.debug( console.debug(
`Data is empty, initializing for ${userNew ? 'new' : 'existing'} user`, `Data is empty, initializing for ${userNew ? 'new' : 'existing'} user`,
@ -304,17 +305,17 @@ export const useUserHighlightStore = defineStore('user_highlight', {
console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`) console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`)
} }
let totalPrefs let highlights
if (dirty) { if (dirty) {
console.debug('Merging the data...') console.debug('Merging the data...')
_verifyPrefs(recent) _verifyHighlights(recent)
_verifyPrefs(stale) _verifyHighlights(stale)
totalPrefs = _mergePrefs(recent.highlight, stale.highlight) highlights = _mergeHighlights(recent.highlight, stale.highlight)
} else { } else {
totalPrefs = recent.highlight highlights = recent.highlight
} }
recent.highlight = { ...defaultState.highlight, ...totalPrefs } recent.highlight = { ...defaultState.highlight, ...highlights }
this.dirty = dirty || needUpload this.dirty = dirty || needUpload
this.cache = recent this.cache = recent