Merge branch 'setttingssync' into shigusegubu-themes3
This commit is contained in:
commit
f3308f463f
4 changed files with 79 additions and 19 deletions
|
|
@ -47,6 +47,10 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
local: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
parentPath: {
|
parentPath: {
|
||||||
type: [String, Array],
|
type: [String, Array],
|
||||||
},
|
},
|
||||||
|
|
@ -259,11 +263,17 @@ export default {
|
||||||
const writePath = `simple.${readPath}`
|
const writePath = `simple.${readPath}`
|
||||||
|
|
||||||
if (!this.timedApplyMode) {
|
if (!this.timedApplyMode) {
|
||||||
useSyncConfigStore().setSimplePrefAndSave({
|
if (this.local) {
|
||||||
path: writePath,
|
useLocalConfigStore().set({
|
||||||
value,
|
path: writePath,
|
||||||
})
|
value,
|
||||||
useSyncConfigStore().pushSyncConfig()
|
})
|
||||||
|
} else {
|
||||||
|
useSyncConfigStore().setSimplePrefAndSave({
|
||||||
|
path: writePath,
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
|
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
|
||||||
console.error("Can't track more than one temporary change")
|
console.error("Can't track more than one temporary change")
|
||||||
|
|
@ -272,18 +282,30 @@ export default {
|
||||||
|
|
||||||
const oldValue = get(this.configSource, readPath)
|
const oldValue = get(this.configSource, readPath)
|
||||||
|
|
||||||
useSyncConfigStore().setPreference({ path: writePath, value })
|
if (this.local) {
|
||||||
|
useLocalConfigStore().setTemporarily({ path: writePath, value })
|
||||||
|
} else {
|
||||||
|
useSyncConfigStore().setPreference({ path: writePath, value })
|
||||||
|
}
|
||||||
|
|
||||||
const confirm = () => {
|
const confirm = () => {
|
||||||
useSyncConfigStore().pushSyncConfig()
|
if (this.local) {
|
||||||
|
useLocalConfigStore().set({ path: writePath, value })
|
||||||
|
} else {
|
||||||
|
useSyncConfigStore().pushSyncConfig()
|
||||||
|
}
|
||||||
useInterfaceStore().clearTemporaryChanges()
|
useInterfaceStore().clearTemporaryChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
const revert = () => {
|
const revert = () => {
|
||||||
useSyncConfigStore().setPreference({
|
if (this.local) {
|
||||||
path: writePath,
|
useLocalConfigStore().unsetTemporarily({ path: writePath, value })
|
||||||
value: oldValue,
|
} else {
|
||||||
})
|
useSyncConfigStore().setPreference({
|
||||||
|
path: writePath,
|
||||||
|
value: oldValue,
|
||||||
|
})
|
||||||
|
}
|
||||||
useInterfaceStore().clearTemporaryChanges()
|
useInterfaceStore().clearTemporaryChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@
|
||||||
:is-local="status.is_local"
|
:is-local="status.is_local"
|
||||||
@parse-ready="onParseReady"
|
@parse-ready="onParseReady"
|
||||||
/>
|
/>
|
||||||
|
{{ mergedConfig }}
|
||||||
<div
|
<div
|
||||||
v-show="shouldShowToggle"
|
v-show="shouldShowToggle"
|
||||||
:class="toggleButtonClasses"
|
:class="toggleButtonClasses"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@ export const defaultState = {
|
||||||
prefsStorage: {
|
prefsStorage: {
|
||||||
...configDefaultState,
|
...configDefaultState,
|
||||||
},
|
},
|
||||||
|
tempStorage: {
|
||||||
|
...configDefaultState
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useLocalConfigStore = defineStore('local_config', {
|
export const useLocalConfigStore = defineStore('local_config', {
|
||||||
|
|
@ -20,6 +23,12 @@ export const useLocalConfigStore = defineStore('local_config', {
|
||||||
set({ path, value }) {
|
set({ path, value }) {
|
||||||
set(this.prefsStorage, path, value)
|
set(this.prefsStorage, path, value)
|
||||||
},
|
},
|
||||||
|
setTemporarily({ path, value }) {
|
||||||
|
set(this.tempStorage, path, value)
|
||||||
|
},
|
||||||
|
unsetTemporarily({ path, value }) {
|
||||||
|
set(this.tempStorage, path, undefined)
|
||||||
|
},
|
||||||
unset({ path, value }) {
|
unset({ path, value }) {
|
||||||
set(this.prefsStorage, path, undefined)
|
set(this.prefsStorage, path, undefined)
|
||||||
},
|
},
|
||||||
|
|
@ -36,7 +45,7 @@ export const useLocalConfigStore = defineStore('local_config', {
|
||||||
const result = Object.fromEntries(
|
const result = Object.fromEntries(
|
||||||
Object.entries(state.prefsStorage).map(([k, v]) => [
|
Object.entries(state.prefsStorage).map(([k, v]) => [
|
||||||
k,
|
k,
|
||||||
v ?? instancePrefs[k],
|
state.tempStorage[k] ?? v ?? instancePrefs[k],
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
@ -44,7 +53,10 @@ export const useLocalConfigStore = defineStore('local_config', {
|
||||||
},
|
},
|
||||||
persist: {
|
persist: {
|
||||||
afterLoad(state) {
|
afterLoad(state) {
|
||||||
return state
|
return {
|
||||||
|
prefStorage: state.prefsStorage,
|
||||||
|
tempStorage: { ...configDefaultState },
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ export const NEW_USER_DATE = new Date('2022-08-04') // date of writing this, bas
|
||||||
|
|
||||||
export const COMMAND_TRIM_FLAGS = 1000
|
export const COMMAND_TRIM_FLAGS = 1000
|
||||||
export const COMMAND_TRIM_FLAGS_AND_RESET = 1001
|
export const COMMAND_TRIM_FLAGS_AND_RESET = 1001
|
||||||
|
export const COMMAND_WIPE_JOURNAL = 1010
|
||||||
|
export const COMMAND_WIPE_JOURNAL_AND_STORAGE = 1011
|
||||||
|
|
||||||
export const defaultState = {
|
export const defaultState = {
|
||||||
// do we need to update data on server?
|
// do we need to update data on server?
|
||||||
|
|
@ -34,7 +36,7 @@ export const defaultState = {
|
||||||
flagStorage: {
|
flagStorage: {
|
||||||
updateCounter: 0, // Counter for most recent update notification seen
|
updateCounter: 0, // Counter for most recent update notification seen
|
||||||
configMigration: 0, // Counter for config -> server-side migrations
|
configMigration: 0, // Counter for config -> server-side migrations
|
||||||
reset: 0, // special flag that can be used to force-reset all flags, debug purposes only
|
reset: 0, // special flag that can be used to force-reset all data, debug purposes only
|
||||||
// special reset codes:
|
// special reset codes:
|
||||||
// 1000: trim keys to those known by currently running FE
|
// 1000: trim keys to those known by currently running FE
|
||||||
// 1001: same as above + reset everything to 0
|
// 1001: same as above + reset everything to 0
|
||||||
|
|
@ -379,16 +381,30 @@ export const _resetFlags = (
|
||||||
result[flag] = 0
|
result[flag] = 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if (totalFlags.reset > 0 && totalFlags.reset < 9000) {
|
|
||||||
console.debug('Received command to reset the flags')
|
|
||||||
allFlagKeys.forEach((flag) => {
|
|
||||||
result[flag] = 0
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
result.reset = 0
|
result.reset = 0
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const _resetPrefs = (
|
||||||
|
totalFlags,
|
||||||
|
totalPrefs,
|
||||||
|
knownKeys = defaultState.flagStorage,
|
||||||
|
) => {
|
||||||
|
// prefs reset functionality
|
||||||
|
if (
|
||||||
|
totalFlags.reset >= COMMAND_WIPE_JOURNAL &&
|
||||||
|
totalFlags.reset <= COMMAND_WIPE_JOURNAL_AND_STORAGE
|
||||||
|
) {
|
||||||
|
console.debug('Received command to reset journals')
|
||||||
|
clearJournals()
|
||||||
|
if (totalFlags.reset === COMMAND_WIPE_JOURNAL_AND_STORAGE) {
|
||||||
|
console.debug('Received command to reset storage')
|
||||||
|
return cloneDeep(defaultState)
|
||||||
|
}
|
||||||
|
} return totalPrefs
|
||||||
|
}
|
||||||
|
|
||||||
export const _doMigrations = (cache, live) => {
|
export const _doMigrations = (cache, live) => {
|
||||||
const data = cache ?? live
|
const data = cache ?? live
|
||||||
|
|
||||||
|
|
@ -578,6 +594,14 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
Object.keys(this).forEach((k) => {
|
Object.keys(this).forEach((k) => {
|
||||||
this[k] = blankState[k]
|
this[k] = blankState[k]
|
||||||
})
|
})
|
||||||
|
this.flagStorage.reset = COMMAND_WIPE_JOURNAL_AND_STORAGE
|
||||||
|
},
|
||||||
|
clearJournals() {
|
||||||
|
this.flagStorage.reset = COMMAND_WIPE_JOURNAL
|
||||||
|
this.prefsStorage._journal = []
|
||||||
|
this.cache.prefsStorage._journal = []
|
||||||
|
this.raw.prefsStorage._journal = []
|
||||||
|
this.pushSyncConfig()
|
||||||
},
|
},
|
||||||
setSyncConfig(userData) {
|
setSyncConfig(userData) {
|
||||||
const live = userData.storage
|
const live = userData.storage
|
||||||
|
|
@ -633,6 +657,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
totalPrefs = recent.prefsStorage
|
totalPrefs = recent.prefsStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalPrefs = _resetPrefs(totalPrefs, totalFlags)
|
||||||
totalFlags = _resetFlags(totalFlags)
|
totalFlags = _resetFlags(totalFlags)
|
||||||
|
|
||||||
recent.flagStorage = { ...flagsTemplate, ...totalFlags }
|
recent.flagStorage = { ...flagsTemplate, ...totalFlags }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue