Skip to content

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

Add settings page to control popup enable/disable (#541)

Leendert de Borst5594c1ad2f07
diff --git a/browser-extensions/chrome/src/app/App.tsx b/browser-extensions/chrome/src/app/App.tsx
index c78b05ca1..b11df477c 100644
--- a/browser-extensions/chrome/src/app/App.tsx
+++ b/browser-extensions/chrome/src/app/App.tsx
@@ -5,7 +5,7 @@ import { useDb } from './context/DbContext';
import { useMinDurationLoading } from './hooks/useMinDurationLoading';
import Header from './components/Layout/Header';
import BottomNav from './components/Layout/BottomNav';
-import Settings from './pages/Settings';
+import AuthSettings from './pages/AuthSettings';
import CredentialsList from './pages/CredentialsList';
import EmailsList from './pages/EmailsList';
import LoadingSpinner from './components/LoadingSpinner';
@@ -13,6 +13,7 @@ import Home from './pages/Home';
import './style.css';
import CredentialDetails from './pages/CredentialDetails';
import EmailDetails from './pages/EmailDetails';
+import Settings from './pages/Settings';
/**
* Route configuration.
@@ -31,17 +32,17 @@ const App: React.FC = () => {
const authContext = useAuth();
const dbContext = useDb();
const [isUserMenuOpen, setIsUserMenuOpen] = useState(false);
- const [currentTab, setCurrentTab] = useState<'credentials' | 'emails'>('credentials');
const [isLoading, setIsLoading] = useMinDurationLoading(true, 150);
// Add these route configurations
const routes: RouteConfig[] = [
{ path: '/', element: <Home />, showBackButton: false },
- { path: '/settings', element: <Settings />, showBackButton: true, title: 'Settings' },
+ { path: '/auth-settings', element: <AuthSettings />, showBackButton: true, title: 'Settings' },
{ path: '/credentials', element: <CredentialsList />, showBackButton: false },
{ path: '/credentials/:id', element: <CredentialDetails />, showBackButton: true, title: 'Credential details' },
{ path: '/emails', element: <EmailsList />, showBackButton: false },
{ path: '/emails/:id', element: <EmailDetails />, showBackButton: true, title: 'Email details' },
+ { path: '/settings', element: <Settings />, showBackButton: true, title: 'Settings' },
];
/**
@@ -94,10 +95,7 @@ const App: React.FC = () => {
</div>
</main>
- <BottomNav
- currentTab={currentTab}
- setCurrentTab={setCurrentTab}
- />
+ <BottomNav />
</div>
</Router>
);
diff --git a/browser-extensions/chrome/src/app/components/Layout/BottomNav.tsx b/browser-extensions/chrome/src/app/components/Layout/BottomNav.tsx
index 2f2e507aa..4dcad8cbd 100644
--- a/browser-extensions/chrome/src/app/components/Layout/BottomNav.tsx
+++ b/browser-extensions/chrome/src/app/components/Layout/BottomNav.tsx
@@ -1,28 +1,21 @@
-import React from 'react';
+import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../../context/AuthContext';
import { useDb } from '../../context/DbContext';
-/**
- * Bottom nav props.
- */
-type BottomNavProps = {
- currentTab: 'credentials' | 'emails';
- setCurrentTab: (tab: 'credentials' | 'emails') => void;
-}
-
/**
* Bottom nav component.
*/
-const BottomNav: React.FC<BottomNavProps> = ({ currentTab, setCurrentTab }) => {
+const BottomNav: React.FC = () => {
const authContext = useAuth();
const dbContext = useDb();
const navigate = useNavigate();
+ const [currentTab, setCurrentTab] = useState<'credentials' | 'emails' | 'settings'>('credentials');
/**
* Handle tab change.
*/
- const handleTabChange = (tab: 'credentials' | 'emails') : void => {
+ const handleTabChange = (tab: 'credentials' | 'emails' | 'settings') : void => {
setCurrentTab(tab);
navigate(`/${tab}`);
};
@@ -45,7 +38,7 @@ const BottomNav: React.FC<BottomNavProps> = ({ currentTab, setCurrentTab }) => {
<div className="flex justify-around items-center h-14">
<button
onClick={() => handleTabChange('credentials')}
- className={`flex flex-col items-center justify-center w-1/2 h-full ${
+ className={`flex flex-col items-center justify-center w-1/3 h-full ${
currentTab === 'credentials' ? 'text-primary-600 dark:text-primary-500' : 'text-gray-500 dark:text-gray-400'
}`}
>
@@ -56,7 +49,7 @@ const BottomNav: React.FC<BottomNavProps> = ({ currentTab, setCurrentTab }) => {
</button>
<button
onClick={() => handleTabChange('emails')}
- className={`flex flex-col items-center justify-center w-1/2 h-full ${
+ className={`flex flex-col items-center justify-center w-1/3 h-full ${
currentTab === 'emails' ? 'text-primary-600 dark:text-primary-500' : 'text-gray-500 dark:text-gray-400'
}`}
>
@@ -65,6 +58,18 @@ const BottomNav: React.FC<BottomNavProps> = ({ currentTab, setCurrentTab }) => {
</svg>
<span className="text-xs mt-1">Emails</span>
</button>
+ <button
+ onClick={() => handleTabChange('settings')}
+ className={`flex flex-col items-center justify-center w-1/3 h-full ${
+ currentTab === 'settings' ? 'text-primary-600 dark:text-primary-500' : 'text-gray-500 dark:text-gray-400'
+ }`}
+ >
+ <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
+ </svg>
+ <span className="text-xs mt-1">Settings</span>
+ </button>
</div>
</div>
);
diff --git a/browser-extensions/chrome/src/app/components/Layout/Header.tsx b/browser-extensions/chrome/src/app/components/Layout/Header.tsx
index aebb2d960..6f0422a9a 100644
--- a/browser-extensions/chrome/src/app/components/Layout/Header.tsx
+++ b/browser-extensions/chrome/src/app/components/Layout/Header.tsx
@@ -46,7 +46,7 @@ const Header: React.FC<HeaderProps> = ({
* Handle settings.
*/
const handleSettings = () : void => {
- navigate('/settings');
+ navigate('/auth-settings');
};
return (
diff --git a/browser-extensions/chrome/src/app/pages/AuthSettings.tsx b/browser-extensions/chrome/src/app/pages/AuthSettings.tsx
new file mode 100644
index 000000000..0b275fbd2
--- /dev/null
+++ b/browser-extensions/chrome/src/app/pages/AuthSettings.tsx
@@ -0,0 +1,125 @@
+import React, { useState, useEffect } from 'react';
+
+type ApiOption = {
+ label: string;
+ value: string;
+};
+
+const DEFAULT_OPTIONS: ApiOption[] = [
+ { label: 'Aliasvault.net', value: 'https://app.aliasvault.net/api' },
+ { label: 'Self-hosted', value: 'custom' }
+];
+
+/**
+ * Auth settings page only shown when user is not logged in.
+ */
+const AuthSettings: React.FC = () => {
+ const [selectedOption, setSelectedOption] = useState<string>('');
+ const [customUrl, setCustomUrl] = useState<string>('');
+ const [customClientUrl, setCustomClientUrl] = useState<string>('');
+
+ useEffect(() => {
+ // Load saved URLs from storage
+ chrome.storage.local.get(['apiUrl', 'clientUrl'], (result) => {
+ const savedUrl = result.apiUrl;
+ const savedClientUrl = result.clientUrl;
+ const matchingOption = DEFAULT_OPTIONS.find(opt => opt.value === savedUrl);
+ if (matchingOption) {
+ setSelectedOption(matchingOption.value);
+ } else if (savedUrl) {
+ setSelectedOption('custom');
+ setCustomUrl(savedUrl);
+ setCustomClientUrl(savedClientUrl || '');
+ } else {
+ setSelectedOption(DEFAULT_OPTIONS[0].value);
+ }
+ });
+ }, []);
+
+ /**
+ * Handle option change
+ */
+ const handleOptionChange = (e: React.ChangeEvent<HTMLSelectElement>) : void => {
+ const value = e.target.value;
+ setSelectedOption(value);
+ if (value !== 'custom') {
+ chrome.storage.local.set({
+ apiUrl: '',
+ clientUrl: '',
+ });
+ }
+ };
+
+ /**
+ * Handle custom API URL change
+ */
+ const handleCustomUrlChange = (e: React.ChangeEvent<HTMLInputElement>) : void => {
+ const value = e.target.value;
+ setCustomUrl(value);
+ chrome.storage.local.set({ apiUrl: value });
+ };
+
+ /**
+ * Handle custom client URL change
+ * @param e
+ */
+ const handleCustomClientUrlChange = (e: React.ChangeEvent<HTMLInputElement>) : void => {
+ const value = e.target.value;
+ setCustomClientUrl(value);
+ chrome.storage.local.set({ clientUrl: value });
+ };
+
+ return (
+ <div className="p-4">
+ <div className="mb-6">
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
+ API Connection
+ </label>
+ <select
+ value={selectedOption}
+ onChange={handleOptionChange}
+ className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
+ >
+ {DEFAULT_OPTIONS.map(option => (
+ <option key={option.value} value={option.value}>
+ {option.label}
+ </option>
+ ))}
+ </select>
+ </div>
+
+ {selectedOption === 'custom' && (
+ <>
+ <div className="mb-6">
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
+ Custom client URL
+ </label>
+ <input
+ id="custom-client-url"
+ type="text"
+ value={customClientUrl}
+ onChange={handleCustomClientUrlChange}
+ placeholder="https://my-aliasvault-instance.com"
+ className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
+ />
+ </div>
+ <div className="mb-6">
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
+ Custom API URL
+ </label>
+ <input
+ id="custom-api-url"
+ type="text"
+ value={customUrl}
+ onChange={handleCustomUrlChange}
+ placeholder="https://my-aliasvault-instance.com/api"
+ className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
+ />
+ </div>
+ </>
+ )}
+ </div>
+ );
+};
+
+export default AuthSettings;
diff --git a/browser-extensions/chrome/src/app/pages/Settings.tsx b/browser-extensions/chrome/src/app/pages/Settings.tsx
index 7052c6eb5..c624ae11d 100644
--- a/browser-extensions/chrome/src/app/pages/Settings.tsx
+++ b/browser-extensions/chrome/src/app/pages/Settings.tsx
@@ -1,123 +1,115 @@
-import React, { useState, useEffect } from 'react';
+import React, { useEffect, useState } from 'react';
+import { DISABLED_SITES_KEY } from '../../contentScript/Popup';
-type ApiOption = {
- label: string;
- value: string;
-};
-
-const DEFAULT_OPTIONS: ApiOption[] = [
- { label: 'Aliasvault.net', value: 'https://app.aliasvault.net/api' },
- { label: 'Self-hosted', value: 'custom' }
-];
+interface PopupSettings {
+ disabledUrls: string[];
+ currentUrl: string;
+ isEnabled: boolean;
+}
-/**
- * Settings page
- */
const Settings: React.FC = () => {
- const [selectedOption, setSelectedOption] = useState<string>('');
- const [customUrl, setCustomUrl] = useState<string>('');
- const [customClientUrl, setCustomClientUrl] = useState<string>('');
+ const [settings, setSettings] = useState<PopupSettings>({
+ disabledUrls: [],
+ currentUrl: '',
+ isEnabled: true
+ });
useEffect(() => {
- // Load saved URLs from storage
- chrome.storage.local.get(['apiUrl', 'clientUrl'], (result) => {
- const savedUrl = result.apiUrl;
- const savedClientUrl = result.clientUrl;
- const matchingOption = DEFAULT_OPTIONS.find(opt => opt.value === savedUrl);
- if (matchingOption) {
- setSelectedOption(matchingOption.value);
- } else if (savedUrl) {
- setSelectedOption('custom');
- setCustomUrl(savedUrl);
- setCustomClientUrl(savedClientUrl || '');
- } else {
- setSelectedOption(DEFAULT_OPTIONS[0].value);
- }
- });
+ loadSettings();
}, []);
- /**
- * Handle option change
- */
- const handleOptionChange = (e: React.ChangeEvent<HTMLSelectElement>) : void => {
- const value = e.target.value;
- setSelectedOption(value);
- if (value !== 'custom') {
- chrome.storage.local.set({
- apiUrl: '',
- clientUrl: '',
+ const getCurrentTab = async () => {
+ const queryOptions = { active: true, currentWindow: true };
+ const [tab] = await chrome.tabs.query(queryOptions);
+ return tab;
+ };
+
+ const loadSettings = async () => {
+ const tab = await getCurrentTab();
+ const currentUrl = new URL(tab.url || '').hostname;
+
+ // Load disabled URLs from chrome.storage.local
+ chrome.storage.local.get([DISABLED_SITES_KEY], (result) => {
+ const disabledUrls = result[DISABLED_SITES_KEY] || [];
+ setSettings({
+ disabledUrls,
+ currentUrl,
+ isEnabled: !disabledUrls.includes(currentUrl)
});
- }
+ });
};
- /**
- * Handle custom API URL change
- */
- const handleCustomUrlChange = (e: React.ChangeEvent<HTMLInputElement>) : void => {
- const value = e.target.value;
- setCustomUrl(value);
- chrome.storage.local.set({ apiUrl: value });
+ const toggleCurrentSite = async () => {
+ const { currentUrl, disabledUrls, isEnabled } = settings;
+ let newDisabledUrls = [...disabledUrls];
+
+ if (isEnabled) {
+ newDisabledUrls.push(currentUrl);
+ } else {
+ newDisabledUrls = newDisabledUrls.filter(url => url !== currentUrl);
+ }
+
+ const storageData = { [DISABLED_SITES_KEY]: newDisabledUrls };
+ await chrome.storage.local.set(storageData);
+
+ setSettings(prev => ({
+ ...prev,
+ disabledUrls: newDisabledUrls,
+ isEnabled: !isEnabled
+ }));
};
- /**
- * Handle custom client URL change
- * @param e
- */
- const handleCustomClientUrlChange = (e: React.ChangeEvent<HTMLInputElement>) : void => {
- const value = e.target.value;
- setCustomClientUrl(value);
- chrome.storage.local.set({ clientUrl: value });
+ const resetSettings = async () => {
+ // Fix: Use DISABLED_SITES_KEY as the key name here too
+ const storageData = { [DISABLED_SITES_KEY]: [] };
+ await chrome.storage.local.set(storageData);
+
+ setSettings(prev => ({
+ ...prev,
+ disabledUrls: [],
+ isEnabled: true
+ }));
};
return (
- <div className="p-4">
- <div className="mb-6">
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
- API Connection
- </label>
- <select
- value={selectedOption}
- onChange={handleOptionChange}
- className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
- >
- {DEFAULT_OPTIONS.map(option => (
- <option key={option.value} value={option.value}>
- {option.label}
- </option>
- ))}
- </select>
+ <div>
+ <div className="flex justify-between items-center">
+ <h2 className="text-gray-900 dark:text-white text-xl mb-4">Popup Settings</h2>
</div>
- {selectedOption === 'custom' && (
- <>
- <div className="mb-6">
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
- Custom client URL
- </label>
- <input
- id="custom-client-url"
- type="text"
- value={customClientUrl}
- onChange={handleCustomClientUrlChange}
- placeholder="https://my-aliasvault-instance.com"
- className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
- />
- </div>
- <div className="mb-6">
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
- Custom API URL
- </label>
- <input
- id="custom-api-url"
- type="text"
- value={customUrl}
- onChange={handleCustomUrlChange}
- placeholder="https://my-aliasvault-instance.com/api"
- className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
- />
+ <div className="space-y-4">
+ <div>
+ <div className="text-gray-500 dark:text-gray-400 space-y-2 mb-4">
+ <p className="text-sm">
+ You can enable or disable the autofill popup per site.
+ </p>
+ </div>
+ <div className="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
+ <div>
+ <p className="text-sm font-medium text-gray-900 dark:text-white">{settings.currentUrl}</p>
+ <p className={`text-sm ${settings.isEnabled ? 'text-gray-600 dark:text-gray-400' : 'text-red-600 dark:text-red-400'}`}>
+ Popup is {settings.isEnabled ? 'enabled' : 'disabled'} for this site
+ </p>
+ </div>
+ <button
+ onClick={toggleCurrentSite}
+ className={`px-4 py-2 rounded-md ${
+ settings.isEnabled
+ ? 'bg-red-500 hover:bg-red-600 text-white'
+ : 'bg-green-500 hover:bg-green-600 text-white'
+ }`}
+ >
+ {settings.isEnabled ? 'Disable' : 'Enable'}
+ </button>
</div>
- </>
- )}
+ </div>
+ <button
+ onClick={resetSettings}
+ className="w-full px-4 py-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 rounded-md text-gray-900 dark:text-white"
+ >
+ (Re)enable popup for all sites
+ </button>
+ </div>
</div>
);
};
diff --git a/browser-extensions/chrome/src/contentScript/Popup.ts b/browser-extensions/chrome/src/contentScript/Popup.ts
index e2e4f65c1..c4d32d901 100644
--- a/browser-extensions/chrome/src/contentScript/Popup.ts
+++ b/browser-extensions/chrome/src/contentScript/Popup.ts
@@ -647,7 +647,7 @@ function createCredentialList(credentials: Credential[]): HTMLElement[] {
return elements;
}
-const DISABLED_SITES_KEY = 'aliasvault_disabled_sites';
+export const DISABLED_SITES_KEY = 'aliasvault_disabled_sites';
/**
* Check if auto-popup is disabled for current site