fix(ext/sw): atomic chrome.storage update in restore_backup

Single set({vaultConfig, imageBase64?}) instead of two sequential sets,
so a partial-write window can't leave vaultConfig pointing to the new
remote while imageBase64 still references the old vault.
This commit is contained in:
adlee-was-taken
2026-04-28 22:01:56 -04:00
parent 2e825a9d33
commit 9ec5e9b4e1

View File

@@ -483,10 +483,11 @@ export async function handle(
repoPath: msg.newRemote.repoPath, repoPath: msg.newRemote.repoPath,
apiToken: msg.newRemote.apiToken, apiToken: msg.newRemote.apiToken,
}; };
await chrome.storage.local.set({ vaultConfig: cfg }); const storageUpdate: Record<string, unknown> = { vaultConfig: cfg };
if (out.reference_jpg) { if (out.reference_jpg) {
await chrome.storage.local.set({ imageBase64: out.reference_jpg }); storageUpdate.imageBase64 = out.reference_jpg;
} }
await chrome.storage.local.set(storageUpdate);
// Make sure the SW's gitHost cache picks up the new config. // Make sure the SW's gitHost cache picks up the new config.
state.gitHost = newHost; state.gitHost = newHost;