Call api.storeSetting only when setting value changes (#2119)

This commit is contained in:
Chenlei Hu
2025-01-01 17:34:58 -05:00
committed by GitHub
parent c77a5cab5b
commit 3d2b9a8d9d
2 changed files with 32 additions and 9 deletions

View File

@@ -24,13 +24,13 @@ function tryMigrateDeprecatedValue(setting: SettingParams, value: any) {
return setting?.migrateDeprecatedValue?.(value) ?? value
}
function onChange(setting: SettingParams, value: any, oldValue: any) {
if (setting?.onChange && value !== oldValue) {
setting.onChange(value)
// Backward compatibility with old settings dialog.
// Some extensions still listens event emitted by the old settings dialog.
app.ui.settings.dispatchChange(setting.id, value, oldValue)
function onChange(setting: SettingParams, newValue: any, oldValue: any) {
if (setting?.onChange) {
setting.onChange(newValue, oldValue)
}
// Backward compatibility with old settings dialog.
// Some extensions still listens event emitted by the old settings dialog.
app.ui.settings.dispatchChange(setting.id, newValue, oldValue)
}
export const useSettingStore = defineStore('setting', () => {
@@ -75,9 +75,10 @@ export const useSettingStore = defineStore('setting', () => {
*/
async function set<K extends keyof Settings>(key: K, value: Settings[K]) {
const newValue = tryMigrateDeprecatedValue(settingsById.value[key], value)
const oldValue = settingValues.value[key]
onChange(settingsById.value[key], newValue, oldValue)
const oldValue = get(key)
if (newValue === oldValue) return
onChange(settingsById.value[key], newValue, oldValue)
settingValues.value[key] = newValue
await api.storeSetting(key, newValue)
}