Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak vault sync flow and indicator in browser extension
Leendert de Borstac9159e35582
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.tsindex cd63acdb1..5a40bf90c 100644--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts@@ -785,8 +785,13 @@ export function handleGetVaultMigrationStatus(): Promise<VaultMigrationKind> {/*** Upgrade local manifest-v1 storage model to the current schema (if needed) and push it.*/-export function handleMigrateVaultManifest(): Promise<VaultManifestMigrationResult> {- return vaultSync.migrateVaultManifest();+export async function handleMigrateVaultManifest(): Promise<VaultManifestMigrationResult> {+ const result = await vaultSync.migrateVaultManifest();+ if (result.success && !result.pushed) {+ // The migrated vault stays dirty; sync it now instead of at the next unrelated trigger.+ void handleFullVaultSync().catch(error => logFailure('Background sync after the vault migration failed', error));+ }+ return result;}/**diff --git a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsxindex 7499ab762..9df384456 100644--- a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx+++ b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx@@ -231,6 +231,10 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }return onMessage('VAULT_SYNC_PHASE', ({ data }) => {setIsSyncing(data.phase === 'pull');setIsUploading(data.phase === 'push');+ if (data.phase === 'idle') {+ // A background sync may have cleared the dirty flag this popup shows.+ void hasUnsyncedUserChangesInStorage().then(setHasUnsyncedUserChanges);+ }});}, []);diff --git a/core/client/src/sync/VaultSync.ts b/core/client/src/sync/VaultSync.tsindex 7cc1bda62..fd7df50d3 100644--- a/core/client/src/sync/VaultSync.ts+++ b/core/client/src/sync/VaultSync.ts@@ -124,6 +124,12 @@ export function syncResult(overrides: Partial<FullVaultSyncResult> = {}): FullVa* Runs the sync engine's operations for one host and persists what each one reported.*/export class VaultSync {+ /**+ * The engine run in flight. Runs queue behind it: two runs against the same stored vault overwrite each other's+ * stores and dirty flag.+ */+ private queue: Promise<unknown> = Promise.resolve();+/*** Create the wrapper.* @param host - how the engine reaches the local vault and the at-rest blob@@ -254,11 +260,15 @@ export class VaultSync {* @param options - what the caller asks beyond what the engine decides* @param overrides - what one operation sets on the request itself: the unlock key resolveVaultKey runs on, or the target of a sharing operation*/- private async run<T extends VaultSyncEngineResultBase>(operation: VaultSyncOperation, options: VaultSyncOptions = {}, overrides: Partial<Pick<VaultSyncEngineRequest, 'encryptionKey' | 'sharing'>> = {}): Promise<T> {- const request = { ...await buildVaultSyncRequest(operation, options), ...overrides };- const result = await runVaultSyncEngine<T>(this.host, request, this.webApi);- await this.persistSyncResult(result);- return result;+ private run<T extends VaultSyncEngineResultBase>(operation: VaultSyncOperation, options: VaultSyncOptions = {}, overrides: Partial<Pick<VaultSyncEngineRequest, 'encryptionKey' | 'sharing'>> = {}): Promise<T> {+ const run = this.queue.then(async () => {+ const request = { ...await buildVaultSyncRequest(operation, options), ...overrides };+ const result = await runVaultSyncEngine<T>(this.host, request, this.webApi);+ await this.persistSyncResult(result);+ return result;+ });+ this.queue = run.catch(() => undefined);+ return run;}/**