Stop the settings write loop between windows

Two or more windows saved the appearance section to each other without end. The host stores object keys in alphabetical order. ThemeSync compared the stored value and the normalized value as JSON text, so a different key order started a new save in each window. Each save replaced settings.json, about 150 times each second. On a SATA SSD without a DRAM cache, these writes stalled all disk access for 6 to 8 seconds, about every 40 seconds.

- ThemeSync compares the two values with sameSettingsValue, which ignores the key order.
- The host skips a write when the section already holds the value, and sends no settings-changed event. This also stops a similar loop in another section.
- New tests: key order in sameSettingsValue, an appearance from the host that needs no new save, and an unchanged host write.
This commit is contained in:
Knotty Wyvern
2026-11-25 07:32:37 -07:00
parent b52eeb14a1
commit 1f3179facc
5 changed files with 97 additions and 5 deletions
+14
View File
@@ -116,3 +116,17 @@ test('A failed write reaches the caller', async () => {
handlers.set('settings_write', () => { throw 'Disk full'; });
await assert.rejects(store.writeSection('customThemes', []), /Disk full/);
});
test('The same data in a different key order is the same settings value', () => {
const saved = { theme: 'harvest-moon', mode: 'dark', transparency: { enabled: true, amount: 18 }, targets: ['app', 'pm-all'] };
// The host sends the keys back in alphabetical order.
const fromHost = { mode: 'dark', targets: ['app', 'pm-all'], theme: 'harvest-moon', transparency: { amount: 18, enabled: true } };
assert.notEqual(JSON.stringify(saved), JSON.stringify(fromHost));
assert.ok(store.sameSettingsValue(saved, fromHost));
assert.ok(!store.sameSettingsValue(saved, { ...fromHost, mode: 'light' }));
assert.ok(!store.sameSettingsValue(saved, { ...fromHost, targets: ['pm-all', 'app'] }), 'The order of an array counts');
assert.ok(!store.sameSettingsValue(saved, { ...fromHost, extra: 1 }));
assert.ok(store.sameSettingsValue('en', 'en'));
assert.ok(store.sameSettingsValue(null, null));
assert.ok(!store.sameSettingsValue(null, {}));
});