Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add identity generator options to browser extension settings (#1571)
Leendert de Borst75d74d46b12f
diff --git a/apps/browser-extension/src/entrypoints/popup/App.tsx b/apps/browser-extension/src/entrypoints/popup/App.tsxindex 53f4a54af..54a0bc05c 100644--- a/apps/browser-extension/src/entrypoints/popup/App.tsx+++ b/apps/browser-extension/src/entrypoints/popup/App.tsx@@ -31,6 +31,7 @@ import AutofillSettings from '@/entrypoints/popup/pages/settings/AutofillSettingimport AutoLockSettings from '@/entrypoints/popup/pages/settings/AutoLockSettings';import ClipboardSettings from '@/entrypoints/popup/pages/settings/ClipboardSettings';import ContextMenuSettings from '@/entrypoints/popup/pages/settings/ContextMenuSettings';+import IdentityGeneratorSettings from '@/entrypoints/popup/pages/settings/IdentityGeneratorSettings';import LanguageSettings from '@/entrypoints/popup/pages/settings/LanguageSettings';import PasskeySettings from '@/entrypoints/popup/pages/settings/PasskeySettings';import Settings from '@/entrypoints/popup/pages/settings/Settings';@@ -203,6 +204,7 @@ const App: React.FC = () => {{ path: '/settings/language', element: <LanguageSettings />, showBackButton: true, title: t('settings.language') },{ path: '/settings/auto-lock', element: <AutoLockSettings />, showBackButton: true, title: t('settings.autoLockTimeout') },{ path: '/settings/passkeys', element: <PasskeySettings />, showBackButton: true, title: t('settings.passkeySettings') },+ { path: '/settings/identity-generator', element: <IdentityGeneratorSettings />, showBackButton: true, title: t('settings.identityGenerator') },], [t]);useEffect(() => {diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsxindex 8dcd0baed..70f59dfe8 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx@@ -1,5 +1,5 @@-import React from 'react';-import { Routes, Route } from 'react-router-dom';+import React, { useRef, useEffect } from 'react';+import { Routes, Route, useLocation } from 'react-router-dom';import { ClipboardCountdownBar } from '@/entrypoints/popup/components/ClipboardCountdownBar';import BottomNav from '@/entrypoints/popup/components/Layout/BottomNav';@@ -30,6 +30,16 @@ type DefaultLayoutProps = {* This is the main layout used for most pages in the extension.*/const DefaultLayout: React.FC<DefaultLayoutProps> = ({ routes, headerButtons, message, children }) => {+ const mainRef = useRef<HTMLElement>(null);+ const location = useLocation();++ // Reset scroll position when route changes+ useEffect(() => {+ if (mainRef.current) {+ mainRef.current.scrollTop = 0;+ }+ }, [location.pathname]);+return (<div className="min-h-screen min-w-[350px] bg-white dark:bg-gray-900 flex flex-col max-h-[600px]"><ClipboardCountdownBar />@@ -40,6 +50,7 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ routes, headerButtons, me/><main+ ref={mainRef}className="flex-1 overflow-y-auto bg-gray-100 dark:bg-gray-900"style={{paddingTop: '64px',diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsxnew file mode 100644index 000000000..3bda71ac2--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsx@@ -0,0 +1,179 @@+import React, { useEffect, useState, useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { useDb } from '@/entrypoints/popup/context/DbContext';+import { useLoading } from '@/entrypoints/popup/context/LoadingContext';+import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';++import { getAvailableLanguages, getAvailableAgeRanges, ILanguageOption, IAgeRangeOption } from '@/utils/dist/core/identity-generator';++/**+ * Identity Generator Settings page component.+ * Allows users to configure default language, gender, and age range for identity generation.+ */+const IdentityGeneratorSettings: React.FC = () => {+ const { t } = useTranslation();+ const { setIsInitialLoading } = useLoading();+ const dbContext = useDb();+ const { executeVaultMutationAsync } = useVaultMutate();++ const [language, setLanguage] = useState<string>('en');+ const [gender, setGender] = useState<string>('random');+ const [ageRange, setAgeRange] = useState<string>('random');+ const [languageOptions, setLanguageOptions] = useState<ILanguageOption[]>([]);+ const [ageRangeOptions, setAgeRangeOptions] = useState<IAgeRangeOption[]>([]);++ const GENDER_OPTIONS = [+ { label: t('settings.identityGeneratorSettings.genderOptions.random'), value: 'random' },+ { label: t('settings.identityGeneratorSettings.genderOptions.male'), value: 'male' },+ { label: t('settings.identityGeneratorSettings.genderOptions.female'), value: 'female' }+ ];++ /**+ * Load settings on mount.+ */+ useEffect(() => {+ const languages = getAvailableLanguages();+ const ranges = getAvailableAgeRanges();+ setLanguageOptions(languages);+ setAgeRangeOptions(ranges);++ if (dbContext?.sqliteClient) {+ const currentLanguage = dbContext.sqliteClient.settings.getEffectiveIdentityLanguage();+ const currentGender = dbContext.sqliteClient.settings.getDefaultIdentityGender();+ const currentAgeRange = dbContext.sqliteClient.settings.getDefaultIdentityAgeRange();++ setLanguage(currentLanguage);+ setGender(currentGender);+ setAgeRange(currentAgeRange);+ }++ setIsInitialLoading(false);+ }, [dbContext?.sqliteClient, setIsInitialLoading]);++ /**+ * Handle language change.+ */+ const handleLanguageChange = useCallback(async (newLanguage: string): Promise<void> => {+ setLanguage(newLanguage);+ if (dbContext?.sqliteClient) {+ await executeVaultMutationAsync(async () => {+ dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityLanguage', newLanguage);+ });+ }+ }, [dbContext?.sqliteClient, executeVaultMutationAsync]);++ /**+ * Handle gender change.+ */+ const handleGenderChange = useCallback(async (newGender: string): Promise<void> => {+ setGender(newGender);+ if (dbContext?.sqliteClient) {+ await executeVaultMutationAsync(async () => {+ dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityGender', newGender);+ });+ }+ }, [dbContext?.sqliteClient, executeVaultMutationAsync]);++ /**+ * Handle age range change.+ */+ const handleAgeRangeChange = useCallback(async (newAgeRange: string): Promise<void> => {+ setAgeRange(newAgeRange);+ if (dbContext?.sqliteClient) {+ await executeVaultMutationAsync(async () => {+ dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityAgeRange', newAgeRange);+ });+ }+ }, [dbContext?.sqliteClient, executeVaultMutationAsync]);++ return (+ <div className="space-y-6">+ {/* Language Section */}+ <section>+ <h3 className="text-md font-semibold text-gray-900 dark:text-white mb-3">+ {t('settings.identityGeneratorSettings.languageSection')}+ </h3>+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="p-4">+ <p className="font-medium text-gray-900 dark:text-white mb-2">+ {t('settings.identityGeneratorSettings.languageSection')}+ </p>+ <p className="text-sm text-gray-600 dark:text-gray-400 mb-3">+ {t('settings.identityGeneratorSettings.languageDescription')}+ </p>+ <select+ value={language}+ onChange={(e) => handleLanguageChange(e.target.value)}+ className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500"+ >+ {languageOptions.map((option) => (+ <option key={option.value} value={option.value}>+ {option.flag} {option.label}+ </option>+ ))}+ </select>+ </div>+ </div>+ </section>++ {/* Gender Section */}+ <section>+ <h3 className="text-md font-semibold text-gray-900 dark:text-white mb-3">+ {t('settings.identityGeneratorSettings.genderSection')}+ </h3>+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="p-4">+ <p className="font-medium text-gray-900 dark:text-white mb-2">+ {t('settings.identityGeneratorSettings.genderSection')}+ </p>+ <p className="text-sm text-gray-600 dark:text-gray-400 mb-3">+ {t('settings.identityGeneratorSettings.genderDescription')}+ </p>+ <select+ value={gender}+ onChange={(e) => handleGenderChange(e.target.value)}+ className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500"+ >+ {GENDER_OPTIONS.map((option) => (+ <option key={option.value} value={option.value}>+ {option.label}+ </option>+ ))}+ </select>+ </div>+ </div>+ </section>++ {/* Age Range Section */}+ <section>+ <h3 className="text-md font-semibold text-gray-900 dark:text-white mb-3">+ {t('settings.identityGeneratorSettings.ageRangeSection')}+ </h3>+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="p-4">+ <p className="font-medium text-gray-900 dark:text-white mb-2">+ {t('settings.identityGeneratorSettings.ageRangeSection')}+ </p>+ <p className="text-sm text-gray-600 dark:text-gray-400 mb-3">+ {t('settings.identityGeneratorSettings.ageRangeDescription')}+ </p>+ <select+ value={ageRange}+ onChange={(e) => handleAgeRangeChange(e.target.value)}+ className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500"+ >+ {ageRangeOptions.map((option) => (+ <option key={option.value} value={option.value}>+ {option.value === 'random' ? t('settings.identityGeneratorSettings.genderOptions.random') : option.label}+ </option>+ ))}+ </select>+ </div>+ </div>+ </section>+ </div>+ );+};++export default IdentityGeneratorSettings;diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsxindex 00cc3ebe9..1266e3825 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx@@ -192,6 +192,13 @@ const Settings: React.FC = () => {navigate('/settings/passkeys');};+ /**+ * Navigate to identity generator settings.+ */+ const navigateToIdentityGeneratorSettings = () : void => {+ navigate('/settings/identity-generator');+ };+return (<>{/* Logout Confirmation Modal */}@@ -279,16 +286,26 @@ const Settings: React.FC = () => {<section><div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"><div className="divide-y divide-gray-200 dark:divide-gray-700">- {/* Vault Unlock Method */}+ {/* Autofill Settings */}<button- onClick={navigateToUnlockMethodSettings}+ onClick={navigateToAutofillSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">- <svg className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />+ <svg+ className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400"+ fill="none"+ stroke="currentColor"+ strokeWidth={2}+ viewBox="0 0 24 24"+ >+ <path+ strokeLinecap="round"+ strokeLinejoin="round"+ d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"+ /></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.unlockMethod.title')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.autofillSettings')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -301,9 +318,9 @@ const Settings: React.FC = () => {</svg></button>- {/* Auto-lock Settings */}+ {/* Passkey Settings */}<button- onClick={navigateToAutoLockSettings}+ onClick={navigateToPasskeySettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -317,10 +334,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"+ d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.autoLockTimeout')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.passkeySettings')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -333,9 +350,31 @@ const Settings: React.FC = () => {</svg></button>- {/* Autofill Settings */}+ {/* Vault Unlock Method */}<button- onClick={navigateToAutofillSettings}+ onClick={navigateToUnlockMethodSettings}+ className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"+ >+ <div className="flex items-center">+ <svg className="w-5 h-5 mr-3 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />+ </svg>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.unlockMethod.title')}</span>+ </div>+ <svg+ className="w-4 h-4 text-gray-400"+ fill="none"+ stroke="currentColor"+ strokeWidth={2}+ viewBox="0 0 24 24"+ >+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />+ </svg>+ </button>++ {/* Auto-lock Settings */}+ <button+ onClick={navigateToAutoLockSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -349,10 +388,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"+ d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.autofillSettings')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.autoLockTimeout')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -365,9 +404,9 @@ const Settings: React.FC = () => {</svg></button>- {/* Passkey Settings */}+ {/* Clipboard Settings */}<button- onClick={navigateToPasskeySettings}+ onClick={navigateToClipboardSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -381,10 +420,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"+ d="M8 7v8a2 2 0 002 2h6M8 7V5a2 2 0 012-2h4.586a1 1 0 01.707.293l4.414 4.414a1 1 0 01.293.707V15a2 2 0 01-2 2h-2M8 7H6a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2v-2"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.passkeySettings')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.clipboardSettings')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -396,17 +435,10 @@ const Settings: React.FC = () => {<path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" /></svg></button>- </div>- </div>- </section>- {/* Additional Settings Section */}- <section>- <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">- <div className="divide-y divide-gray-200 dark:divide-gray-700">- {/* Clipboard Settings */}+ {/* Language Settings */}<button- onClick={navigateToClipboardSettings}+ onClick={navigateToLanguageSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -420,10 +452,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M8 7v8a2 2 0 002 2h6M8 7V5a2 2 0 012-2h4.586a1 1 0 01.707.293l4.414 4.414a1 1 0 01.293.707V15a2 2 0 01-2 2h-2M8 7H6a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2v-2"+ d="M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.clipboardSettings')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.language')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -435,10 +467,17 @@ const Settings: React.FC = () => {<path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" /></svg></button>+ </div>+ </div>+ </section>- {/* Context Menu Settings */}+ {/* Generator Settings Section */}+ <section>+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">+ <div className="divide-y divide-gray-200 dark:divide-gray-700">+ {/* Identity Generator Settings */}<button- onClick={navigateToContextMenuSettings}+ onClick={navigateToIdentityGeneratorSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -452,10 +491,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M4 6h16M4 12h16m-7 6h7"+ d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.contextMenuSettings')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.identityGenerator')}</span></div><svgclassName="w-4 h-4 text-gray-400"@@ -468,9 +507,9 @@ const Settings: React.FC = () => {</svg></button>- {/* Language Settings */}+ {/* Context Menu Settings */}<button- onClick={navigateToLanguageSettings}+ onClick={navigateToContextMenuSettings}className="w-full px-4 py-3 flex items-center justify-between hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"><div className="flex items-center">@@ -484,10 +523,10 @@ const Settings: React.FC = () => {<pathstrokeLinecap="round"strokeLinejoin="round"- d="M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"+ d="M4 6h16M4 12h16m-7 6h7"/></svg>- <span className="text-gray-900 dark:text-white text-left">{t('settings.language')}</span>+ <span className="text-gray-900 dark:text-white text-left">{t('settings.contextMenuSettings')}</span></div><svgclassName="w-4 h-4 text-gray-400"diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex 41364208b..60ba8fa9e 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -403,6 +403,21 @@"clientUrlRequired": "Client URL is required","clientUrlInvalid": "Please enter a valid client URL"},+ "identityGenerator": "Identity Generator",+ "identityGeneratorSettings": {+ "description": "Configure the default language and gender preference for generating new identities.",+ "languageSection": "Language",+ "languageDescription": "Set the language that will be used when generating new identities.",+ "genderSection": "Gender",+ "genderDescription": "Set the gender preference for generating new identities.",+ "ageRangeSection": "Age Range",+ "ageRangeDescription": "Set the age range for generating new identities.",+ "genderOptions": {+ "random": "Random",+ "male": "Male",+ "female": "Female"+ }+ },"unlockMethod": {"title": "Vault Unlock Method","introText": "Choose how you want to unlock your vault. You can use your master password (always available) or set up a PIN code for faster access. After 3 failed PIN attempts, you'll need to use your master password.",