Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add option to automatically close vault unlock success popup in browser extension (#1689)
Leendert de Borstbf2475c4cc78
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/UnlockSuccess.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/UnlockSuccess.tsxindex b240c77ef..6c2f9ec9a 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/UnlockSuccess.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/UnlockSuccess.tsx@@ -1,7 +1,13 @@-import React from 'react';+import React, { useEffect, useState, useRef, useCallback } from 'react';import { useTranslation } from 'react-i18next';import { useNavigate } from 'react-router-dom';+import { CountdownBar, ICountdownBarHandle } from '@/entrypoints/popup/components/CountdownBar';++import { LocalPreferencesService } from '@/utils/LocalPreferencesService';++const AUTO_CLOSE_COUNTDOWN_SECONDS = 2.5;+/*** Unlock success component shown when the vault is successfully unlocked in a separate popup* asking the user if they want to close the popup.@@ -9,11 +15,73 @@ import { useNavigate } from 'react-router-dom';const UnlockSuccess: React.FC = () => {const navigate = useNavigate();const { t } = useTranslation();+ const [autoCloseEnabled, setAutoCloseEnabled] = useState<boolean>(false);+ const [countdown, setCountdown] = useState<number | null>(null);+ const [isLoading, setIsLoading] = useState<boolean>(true);+ const countdownTimerRef = useRef<ReturnType<typeof setInterval> | null>(null);+ const countdownBarRef = useRef<ICountdownBarHandle>(null);++ /**+ * Clear the countdown timer+ */+ const clearCountdownTimer = useCallback((): void => {+ if (countdownTimerRef.current) {+ clearInterval(countdownTimerRef.current);+ countdownTimerRef.current = null;+ }+ }, []);++ /**+ * Start the auto-close countdown+ */+ const startCountdown = useCallback((): void => {+ clearCountdownTimer();+ setCountdown(AUTO_CLOSE_COUNTDOWN_SECONDS);++ // Start the animation bar+ countdownBarRef.current?.startAnimation(AUTO_CLOSE_COUNTDOWN_SECONDS);++ countdownTimerRef.current = setInterval(() => {+ setCountdown((prev) => {+ if (prev === null || prev <= 1) {+ clearCountdownTimer();+ window.close();+ return null;+ }+ return prev - 1;+ });+ }, 1000);+ }, [clearCountdownTimer]);++ /**+ * Stop the auto-close countdown+ */+ const stopCountdown = useCallback((): void => {+ clearCountdownTimer();+ setCountdown(null);+ countdownBarRef.current?.stopAnimation();+ }, [clearCountdownTimer]);++ /**+ * Handle checkbox change+ */+ const handleAutoCloseChange = async (checked: boolean): Promise<void> => {+ setAutoCloseEnabled(checked);+ await LocalPreferencesService.setAutoCloseUnlockPopup(checked);++ if (checked) {+ startCountdown();+ } else {+ stopCountdown();+ }+ };/*** Handle browsing vault contents - navigate to items page and reset mode parameter*/const handleBrowseVaultContents = (): void => {+ stopCountdown();+// Remove mode=inline from URL before navigatingconst url = new URL(window.location.href);url.searchParams.delete('mode');@@ -23,8 +91,48 @@ const UnlockSuccess: React.FC = () => {navigate('/items');};+ /**+ * Handle close popup button click+ */+ const handleClosePopup = (): void => {+ stopCountdown();+ window.close();+ };++ // Load saved preference and start countdown if enabled+ useEffect(() => {+ /**+ * Load the auto-close preference from storage+ */+ const loadPreference = async (): Promise<void> => {+ const enabled = await LocalPreferencesService.getAutoCloseUnlockPopup();+ setAutoCloseEnabled(enabled);+ setIsLoading(false);++ if (enabled) {+ // Use setTimeout to ensure the CountdownBar component has mounted+ setTimeout(() => {+ startCountdown();+ }, 0);+ }+ };++ loadPreference();++ return (): void => {+ clearCountdownTimer();+ };+ }, [clearCountdownTimer, startCountdown]);+return (<div className="flex flex-col items-center justify-center p-6 text-center">+ {/* Countdown bar at the top */}+ <CountdownBar+ ref={countdownBarRef}+ isVisible={countdown !== null}+ colorClass="bg-primary-500"+ />+<div className="mb-4 text-green-600 dark:text-green-400"><svg className="w-12 h-12 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />@@ -36,9 +144,10 @@ const UnlockSuccess: React.FC = () => {<p className="mb-6 text-gray-600 dark:text-gray-400">{t('auth.unlockSuccessDescription')}</p>+<div className="space-y-3 w-full"><button- onClick={() => window.close()}+ onClick={handleClosePopup}className="w-full px-4 py-2 text-white bg-primary-600 rounded hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2">{t('auth.closePopup')}@@ -50,6 +159,20 @@ const UnlockSuccess: React.FC = () => {{t('auth.browseVault')}</button></div>++ {/* Auto-close checkbox at the bottom with subtle styling */}+ <div className="w-full mt-6 pt-4 border-t border-gray-200 dark:border-gray-700">+ <label className="flex items-center justify-center gap-2 cursor-pointer text-xs text-gray-400 dark:text-gray-500">+ <input+ type="checkbox"+ checked={autoCloseEnabled}+ onChange={(e) => handleAutoCloseChange(e.target.checked)}+ disabled={isLoading}+ className="w-3.5 h-3.5 rounded border-gray-300 text-gray-400 focus:ring-gray-400 dark:border-gray-600 dark:bg-gray-700"+ />+ <span>{t('auth.autoCloseUnlockPopup')}</span>+ </label>+ </div></div>);};diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex d4078a07a..1c6ad71a7 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -24,6 +24,8 @@"unlockSuccessDescription": "You can now use autofill in login forms in your browser.","closePopup": "Close this popup","browseVault": "Browse vault contents",+ "autoCloseUnlockPopup": "Auto-close on future sign ins",+ "closingIn": "Closing in {{seconds}}s...","connectingTo": "Connecting to","switchAccounts": "Switch accounts?","loginWithMobile": "Log in using Mobile App",diff --git a/apps/browser-extension/src/utils/LocalPreferencesService.ts b/apps/browser-extension/src/utils/LocalPreferencesService.tsindex 8cfa730fb..d5068d37f 100644--- a/apps/browser-extension/src/utils/LocalPreferencesService.ts+++ b/apps/browser-extension/src/utils/LocalPreferencesService.ts@@ -29,6 +29,7 @@ const KEYS = {// UI preferencesSHOW_FOLDERS: 'local:aliasvault_show_folders',+ AUTO_CLOSE_UNLOCK_POPUP: 'local:aliasvault_auto_close_unlock_popup',// Session/Navigation statePENDING_REDIRECT_URL: 'session:pendingRedirectUrl',@@ -65,6 +66,22 @@ export const LocalPreferencesService = {await storage.setItem(KEYS.SHOW_FOLDERS, showFolders);},+ /**+ * Get the auto-close unlock popup preference.+ * @returns Whether to auto-close the popup after unlocking. Defaults to true.+ */+ async getAutoCloseUnlockPopup(): Promise<boolean> {+ const value = await storage.getItem(KEYS.AUTO_CLOSE_UNLOCK_POPUP) as boolean | null;+ return value ?? true;+ },++ /**+ * Set the auto-close unlock popup preference.+ */+ async setAutoCloseUnlockPopup(enabled: boolean): Promise<void> {+ await storage.setItem(KEYS.AUTO_CLOSE_UNLOCK_POPUP, enabled);+ },+/*** Get whether the global autofill popup is enabled.* @returns Whether autofill popup is globally enabled. Defaults to true.