Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak browser extension vault sync indicator to only show syncing when downloading a newer vault (#1737)

Leendert de Borst02a5a25a2700
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.ts
index 27b8e5958..14cbdef72 100644
--- a/apps/browser-extension/src/entrypoints/background.ts
+++ b/apps/browser-extension/src/entrypoints/background.ts
@@ -11,7 +11,7 @@ import { handleGetWebAuthnSettings, handleWebAuthnCreate, handleWebAuthnGet, han
import { handleOpenPopup, handlePopupWithItem, handleOpenPopupCreateCredential, handleToggleContextMenu } from '@/entrypoints/background/PopupMessageHandler';
import { handleStoreSavePromptState, handleGetSavePromptState, handleClearSavePromptState, handleStoreLastAutofilled, handleGetLastAutofilled, handleClearLastAutofilled } from '@/entrypoints/background/SavePromptStateHandler';
import { handleStoreTwoFactorState, handleGetTwoFactorState, handleClearTwoFactorState } from '@/entrypoints/background/TwoFactorStateHandler';
-import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearSession, handleClearVaultData, handleLockVault, handleCreateItem, handleGetFilteredItems, handleGetSearchItems, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVaultMetadata, handleSyncVault, handleUploadVault, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetSyncState, handleMarkVaultClean, handleGetServerRevision, handleFullVaultSync, handleCheckLoginDuplicate, handleSaveLoginCredential, handleAddUrlToCredential, handleGetLoginSaveSettings, handleSetLoginSaveEnabled, handleGetItemsWithTotp, handleSearchItemsWithTotp, handleGetTotpSecrets, handleGenerateTotpCode } from '@/entrypoints/background/VaultMessageHandler';
+import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearSession, handleClearVaultData, handleLockVault, handleCreateItem, handleGetFilteredItems, handleGetSearchItems, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVaultMetadata, handleSyncVault, handleUploadVault, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetSyncState, handleMarkVaultClean, handleGetServerRevision, handleCheckSyncStatus, handleFullVaultSync, handleCheckLoginDuplicate, handleSaveLoginCredential, handleAddUrlToCredential, handleGetLoginSaveSettings, handleSetLoginSaveEnabled, handleGetItemsWithTotp, handleSearchItemsWithTotp, handleGetTotpSecrets, handleGenerateTotpCode } from '@/entrypoints/background/VaultMessageHandler';
import { EncryptionKeyDerivationParams } from "@/utils/dist/core/models/metadata";
import type { LoginResponse } from "@/utils/dist/core/models/webapi";
@@ -51,6 +51,7 @@ export default defineBackground({
onMessage('CREATE_ITEM', ({ data }) => handleCreateItem(data));
onMessage('UPLOAD_VAULT', () => handleUploadVault());
onMessage('SYNC_VAULT', () => handleSyncVault());
+ onMessage('CHECK_SYNC_STATUS', () => handleCheckSyncStatus());
onMessage('FULL_VAULT_SYNC', () => handleFullVaultSync());
onMessage('LOCK_VAULT', () => handleLockVault());
onMessage('CLEAR_SESSION', () => handleClearSession());
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index a10402f74..fa5583f96 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -917,6 +917,24 @@ export async function handleGetServerRevision(): Promise<number> {
return revision ?? 0;
}
+/**
+ * Result of a sync status check (without doing actual sync).
+ */
+export type SyncStatusCheckResult = {
+ /** True if check succeeded */
+ success: boolean;
+ /** True if server has a newer vault to download */
+ hasNewerVault: boolean;
+ /** True if we have local changes to upload */
+ hasDirtyChanges: boolean;
+ /** True if offline (server unavailable) */
+ isOffline: boolean;
+ /** True if user needs to be logged out */
+ requiresLogout: boolean;
+ /** Error key for translation */
+ errorKey?: string;
+};
+
/**
* Result of a full vault sync operation.
*/
@@ -936,6 +954,64 @@ export type FullVaultSyncResult = {
requiresLogout: boolean;
};
+/**
+ * Quick check if a sync is needed without doing the actual sync.
+ * Used by popup to show syncing indicator before starting the actual sync.
+ */
+export async function handleCheckSyncStatus(): Promise<SyncStatusCheckResult> {
+ const webApi = new WebApiService();
+
+ try {
+ // Check if user is logged in
+ const authStatus = await handleCheckAuthStatus();
+ if (!authStatus.isLoggedIn || authStatus.isVaultLocked) {
+ return { success: false, hasNewerVault: false, hasDirtyChanges: false, isOffline: false, requiresLogout: false };
+ }
+
+ // Get current sync state
+ const syncState = await handleGetSyncState();
+
+ // Check app status and vault revision
+ const statusResponse = await webApi.getStatus();
+
+ // Check if server is unavailable
+ if (statusResponse.serverVersion === '0.0.0') {
+ return { success: true, hasNewerVault: false, hasDirtyChanges: syncState.isDirty, isOffline: true, requiresLogout: false };
+ }
+
+ // Validate status response
+ const statusError = webApi.validateStatusResponse(statusResponse);
+ if (statusError) {
+ if (statusError === 'clientVersionNotSupported' || statusError === 'serverVersionNotSupported') {
+ return { success: false, hasNewerVault: false, hasDirtyChanges: false, isOffline: false, requiresLogout: true, errorKey: statusError };
+ }
+ return { success: false, hasNewerVault: false, hasDirtyChanges: false, isOffline: false, requiresLogout: false, errorKey: statusError };
+ }
+
+ // Check if the SRP salt has changed (password change detection)
+ const storedEncryptionParams = await handleGetEncryptionKeyDerivationParams();
+ if (storedEncryptionParams && statusResponse.srpSalt && statusResponse.srpSalt !== storedEncryptionParams.salt) {
+ return { success: false, hasNewerVault: false, hasDirtyChanges: false, isOffline: false, requiresLogout: true, errorKey: 'passwordChanged' };
+ }
+
+ return {
+ success: true,
+ hasNewerVault: statusResponse.vaultRevision > syncState.serverRevision,
+ hasDirtyChanges: syncState.isDirty,
+ isOffline: false,
+ requiresLogout: false
+ };
+ } catch (err) {
+ // Network error - treat as offline
+ if (err instanceof NetworkError) {
+ const syncState = await handleGetSyncState();
+ return { success: true, hasNewerVault: false, hasDirtyChanges: syncState.isDirty, isOffline: true, requiresLogout: false };
+ }
+
+ return { success: false, hasNewerVault: false, hasDirtyChanges: false, isOffline: false, requiresLogout: false };
+ }
+}
+
/**
* Full vault sync orchestration that runs entirely in background context.
* This ensures sync completes even if popup closes mid-operation.
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/ServerSyncIndicator.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/ServerSyncIndicator.tsx
index 61cdbf096..15a43ede7 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/ServerSyncIndicator.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/ServerSyncIndicator.tsx
@@ -19,8 +19,9 @@ const MIN_SYNC_DISPLAY_TIME = 1000;
* Priority order (highest to lowest):
* 1. Offline (amber) - network unavailable, clickable to retry
* 2. Syncing (green spinner) - downloading new vault (minimum display time)
- * 3. Pending (blue) - local changes waiting to be uploaded, clickable to retry
- * 4. Hidden - when synced
+ * 3. Uploading (blue spinner) - uploading local changes to server
+ * 4. Pending (blue pulsing) - local changes waiting to be uploaded, clickable to retry
+ * 5. Hidden - when synced
*
* Note: The syncing indicator only appears when actually downloading a new vault,
* not during routine checks where nothing changed.
@@ -75,6 +76,11 @@ const ServerSyncIndicator: React.FC = () => {
setIsRetrying(true);
+ // If we have local changes, show uploading indicator
+ if (dbContext.isDirty) {
+ dbContext.setIsUploading(true);
+ }
+
try {
const result = await sendMessage('FULL_VAULT_SYNC', {}, 'background') as FullVaultSyncResult;
@@ -105,6 +111,7 @@ const ServerSyncIndicator: React.FC = () => {
console.error('Retry sync error:', error);
} finally {
setIsRetrying(false);
+ dbContext.setIsUploading(false);
}
}, [isRetrying, dbContext, app, t]);
@@ -178,7 +185,25 @@ const ServerSyncIndicator: React.FC = () => {
);
}
- // Priority 3: Pending indicator (clickable to force sync) - icon only
+ // Priority 3: Uploading indicator (not clickable, shows progress)
+ if (dbContext.isUploading) {
+ return (
+ <div
+ className="flex items-center gap-1.5 px-2 py-1 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 rounded-md text-xs font-medium"
+ >
+ <svg className="w-3.5 h-3.5 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
+ />
+ </svg>
+ </div>
+ );
+ }
+
+ // Priority 4: Pending indicator (clickable to force sync) - icon only
if (dbContext.isDirty) {
return (
<button
diff --git a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
index 9d088b31b..53c1235c3 100644
--- a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
@@ -32,18 +32,26 @@ type DbContextType = {
*/
isDirty: boolean;
/**
- * True if a background sync is in progress.
+ * True if a background sync (download) is in progress.
*/
isSyncing: boolean;
+ /**
+ * True if an upload to server is in progress.
+ */
+ isUploading: boolean;
/**
* Current server revision number.
*/
serverRevision: number;
setIsOffline: (offline: boolean) => Promise<void>;
/**
- * Set the syncing state.
+ * Set the syncing (download) state.
*/
setIsSyncing: (syncing: boolean) => void;
+ /**
+ * Set the uploading state.
+ */
+ setIsUploading: (uploading: boolean) => void;
/**
* Check if email errors should be suppressed.
* Errors are suppressed when vault has local changes not yet synced,
@@ -104,10 +112,15 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
const [isDirty, setIsDirty] = useState(false);
/**
- * Syncing state - true if a background sync is in progress.
+ * Syncing state - true if a background sync (download) is in progress.
*/
const [isSyncing, setIsSyncing] = useState(false);
+ /**
+ * Uploading state - true if an upload to server is in progress.
+ */
+ const [isUploading, setIsUploading] = useState(false);
+
/**
* Server revision number.
*/
@@ -298,9 +311,11 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
getIsOffline,
isDirty,
isSyncing,
+ isUploading,
serverRevision,
setIsOffline,
setIsSyncing,
+ setIsUploading,
shouldSuppressEmailErrors,
loadDatabase,
loadStoredDatabase,
@@ -310,7 +325,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
getVaultMetadata,
refreshSyncState,
hasPendingMigrations,
- }), [sqliteClient, dbInitialized, dbAvailable, isOffline, getIsOffline, isDirty, isSyncing, serverRevision, setIsOffline, shouldSuppressEmailErrors, loadDatabase, loadStoredDatabase, storeEncryptionKey, storeEncryptionKeyDerivationParams, clearDatabase, getVaultMetadata, refreshSyncState, hasPendingMigrations]);
+ }), [sqliteClient, dbInitialized, dbAvailable, isOffline, getIsOffline, isDirty, isSyncing, isUploading, serverRevision, setIsOffline, shouldSuppressEmailErrors, loadDatabase, loadStoredDatabase, storeEncryptionKey, storeEncryptionKeyDerivationParams, clearDatabase, getVaultMetadata, refreshSyncState, hasPendingMigrations]);
return (
<DbContext.Provider value={contextValue}>
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
index 00f82905a..112ecd543 100644
--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
@@ -62,6 +62,8 @@ export function useVaultMutate(): {
* so the popup shows the merged data.
*/
const triggerBackgroundSync = useCallback((): void => {
+ dbContext.setIsUploading(true);
+
/*
* Fire-and-forget: send message to background without awaiting.
* The background script will handle the full sync orchestration
@@ -76,6 +78,8 @@ export function useVaultMutate(): {
await dbContext.refreshSyncState();
}).catch((error) => {
console.error('Background sync error:', error);
+ }).finally(() => {
+ dbContext.setIsUploading(false);
});
}, [dbContext]);
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
index 08dd5023f..43da712f8 100644
--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
@@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { sendMessage } from 'webext-bridge/popup';
-import type { FullVaultSyncResult } from '@/entrypoints/background/VaultMessageHandler';
+import type { FullVaultSyncResult, SyncStatusCheckResult } from '@/entrypoints/background/VaultMessageHandler';
import { useApp } from '@/entrypoints/popup/context/AppContext';
import { useDb } from '@/entrypoints/popup/context/DbContext';
@@ -48,6 +48,26 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
onStatus?.(t('common.checkingVaultUpdates'));
+ /*
+ * Quick check if sync is needed, this tells us if server has newer vault
+ * or if we have local changes to upload, so we can show the appropriate indicator in UI.
+ */
+ const statusCheck = await sendMessage('CHECK_SYNC_STATUS', {}, 'background') as SyncStatusCheckResult;
+
+ // Handle logout requirement from status check
+ if (statusCheck.requiresLogout) {
+ const errorMessage = statusCheck.errorKey ? t('common.errors.' + statusCheck.errorKey) : undefined;
+ await app.logout(errorMessage);
+ return false;
+ }
+
+ // Show appropriate indicator based on what sync will do
+ if (statusCheck.hasNewerVault) {
+ dbContext.setIsSyncing(true);
+ } else if (statusCheck.hasDirtyChanges && !statusCheck.isOffline) {
+ dbContext.setIsUploading(true);
+ }
+
// Delegate to background script for full sync orchestration
const result = await sendMessage('FULL_VAULT_SYNC', {}, 'background') as FullVaultSyncResult;
@@ -85,9 +105,8 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
return false;
}
- // If we got a new vault, show syncing indicator and reload database into memory
+ // If we got a new vault, reload database into memory
if (result.hasNewVault) {
- dbContext.setIsSyncing(true);
onStatus?.(t('common.syncingUpdatedVault'));
await dbContext.loadStoredDatabase();
}
@@ -103,8 +122,9 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
onError?.(errorMessage);
return false;
} finally {
- // Always clear syncing state when done
+ // Always clear syncing/uploading states when done
dbContext.setIsSyncing(false);
+ dbContext.setIsUploading(false);
}
}, [app, dbContext, t]);