Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor placeholder icon fallback to constants (#1404)
Leendert de Borst57920b2800b4
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex ce85cae33..056b4925c 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -2,7 +2,7 @@ import { sendMessage } from 'webext-bridge/content-script';import { fillItem } from '@/entrypoints/contentScript/Form';-import { DISABLED_SITES_KEY, TEMPORARY_DISABLED_SITES_KEY, GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY, AUTOFILL_MATCHING_MODE_KEY, CUSTOM_EMAIL_HISTORY_KEY, CUSTOM_USERNAME_HISTORY_KEY } from '@/utils/Constants';+import { DISABLED_SITES_KEY, TEMPORARY_DISABLED_SITES_KEY, GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY, AUTOFILL_MATCHING_MODE_KEY, CUSTOM_EMAIL_HISTORY_KEY, CUSTOM_USERNAME_HISTORY_KEY, PLACEHOLDER_ICON_SVG } from '@/utils/Constants';import { AutofillMatchingMode } from '@/utils/credentialMatcher/CredentialMatcher';import { CreateIdentityGenerator, IdentityHelperUtils } from '@/utils/dist/core/identity-generator';import type { Item, ItemField } from '@/utils/dist/core/models/vault';@@ -727,11 +727,15 @@ function createItemList(items: Item[], input: HTMLInputElement, rootContainer: Hconst itemInfo = document.createElement('div');itemInfo.className = 'av-credential-info';- const imgElement = document.createElement('img');- imgElement.className = 'av-credential-logo';- imgElement.src = SqliteClient.imgSrcFromBytes(item.Logo);-- itemInfo.appendChild(imgElement);+ const logoSrc = SqliteClient.imgSrcFromBytes(item.Logo);+ const logoContainer = document.createElement('div');+ logoContainer.className = 'av-credential-logo';+ if (logoSrc) {+ logoContainer.innerHTML = `<img src="${logoSrc}" alt="" style="width:100%;height:100%;">`;+ } else {+ logoContainer.innerHTML = PLACEHOLDER_ICON_SVG;+ }+ itemInfo.appendChild(logoContainer);const itemTextContainer = document.createElement('div');itemTextContainer.className = 'av-credential-text';diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemIcon.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemIcon.tsxindex 9409db24d..fb5482d32 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemIcon.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemIcon.tsx@@ -1,5 +1,6 @@import React from 'react';+import { PLACEHOLDER_ICON_SVG } from '@/utils/Constants';import type { Item } from '@/utils/dist/core/models/vault';import { FieldKey, ItemTypes } from '@/utils/dist/core/models/vault';import SqliteClient from '@/utils/SqliteClient';@@ -250,22 +251,24 @@ const ItemIcon: React.FC<ItemIconProps> = ({ item, className = 'w-8 h-8' }) => {}// For Login/Alias types, use Logo if available, otherwise placeholder- if (item.Logo && item.Logo.length > 0) {+ const logoSrc = item.Logo && item.Logo.length > 0 ? SqliteClient.imgSrcFromBytes(item.Logo) : null;++ if (logoSrc) {return (<img- src={SqliteClient.imgSrcFromBytes(item.Logo)}+ src={logoSrc}alt={item.Name || 'Item'}className={`${className} flex-shrink-0`}onError={(e) => {// On error, replace with placeholder iconconst target = e.target as HTMLImageElement;target.style.display = 'none';- // Insert placeholder SVG (key icon)const parent = target.parentElement;if (parent) {const placeholder = document.createElement('div');- placeholder.innerHTML = `<svg class="${className}" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="6.5" stroke="#f49541" stroke-width="2.5"/><circle cx="10" cy="10" r="2.5" stroke="#f49541" stroke-width="2"/><path d="M15 15L27 27" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/><path d="M19 19L23 15" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/><path d="M24 24L28 20" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/></svg>`;- parent.insertBefore(placeholder.firstChild!, target);+ placeholder.className = className;+ placeholder.innerHTML = PLACEHOLDER_ICON_SVG;+ parent.insertBefore(placeholder, target);}}}/>diff --git a/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx b/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsxindex 66ea2a54f..f39d08749 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx@@ -7,6 +7,7 @@ import Alert from '@/entrypoints/popup/components/Alert';import Button from '@/entrypoints/popup/components/Button';import PasskeyBypassDialog from '@/entrypoints/popup/components/Dialogs/PasskeyBypassDialog';import { FormInput } from '@/entrypoints/popup/components/Forms/FormInput';+import ItemIcon from '@/entrypoints/popup/components/Items/ItemIcon';import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useLoading } from '@/entrypoints/popup/context/LoadingContext';@@ -21,7 +22,6 @@ import { FieldKey, FieldTypes, ItemTypes, getFieldValue } from '@/utils/dist/corimport { PasskeyAuthenticator } from '@/utils/passkey/PasskeyAuthenticator';import { PasskeyHelper } from '@/utils/passkey/PasskeyHelper';import type { CreateRequest, PasskeyCreateCredentialResponse, PendingPasskeyCreateRequest } from '@/utils/passkey/types';-import { SqliteClient } from '@/utils/SqliteClient';import { storage } from "#imports";@@ -683,13 +683,6 @@ const PasskeyCreate: React.FC = () => {><div className="flex items-center justify-between"><div className="flex items-center flex-1 min-w-0">- {item.Logo && (- <img- src={SqliteClient.imgSrcFromBytes(item.Logo)}- alt=""- className="w-8 h-8 rounded mr-3 flex-shrink-0"- />- )}<div className="flex-1 min-w-0"><div className="font-medium text-gray-900 dark:text-white text-sm truncate">{item.Name}diff --git a/apps/browser-extension/src/utils/Constants.ts b/apps/browser-extension/src/utils/Constants.tsindex 61f51a305..3ccd3bb91 100644--- a/apps/browser-extension/src/utils/Constants.ts+++ b/apps/browser-extension/src/utils/Constants.ts@@ -14,3 +14,9 @@ export const PENDING_REDIRECT_URL_KEY = 'session:pendingRedirectUrl';export const CUSTOM_EMAIL_HISTORY_KEY = 'local:aliasvault_custom_email_history';export const CUSTOM_USERNAME_HISTORY_KEY = 'local:aliasvault_custom_username_history';export const SKIP_FORM_RESTORE_KEY = 'local:aliasvault_skip_form_restore';++/**+ * Placeholder SVG for items without a logo (key icon).+ * Used by both ItemIcon.tsx (React) and Popup.ts (content script).+ */+export const PLACEHOLDER_ICON_SVG = `<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="6.5" stroke="#f49541" stroke-width="2.5"/><circle cx="10" cy="10" r="2.5" stroke="#f49541" stroke-width="2"/><path d="M15 15L27 27" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/><path d="M19 19L23 15" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/><path d="M24 24L28 20" stroke="#f49541" stroke-width="2.5" stroke-linecap="round"/></svg>`;diff --git a/apps/browser-extension/src/utils/SqliteClient.ts b/apps/browser-extension/src/utils/SqliteClient.tsindex 7e5bc3b4c..1e0ff53e8 100644--- a/apps/browser-extension/src/utils/SqliteClient.ts+++ b/apps/browser-extension/src/utils/SqliteClient.ts@@ -16,11 +16,6 @@ import {import type { IDatabaseClient, SqliteBindValue } from './db/BaseRepository';-/**- * Placeholder base64 image for credentials without a logo.- */-const placeholderBase64 = 'UklGRjoEAABXRUJQVlA4IC4EAAAwFwCdASqAAIAAPpFCm0olo6Ihp5IraLASCWUA0eb/0s56RrLtCnYfLPiBshdXWMx8j1Ez65f169iA4xUDBTEV6ylMQeCIj2b7RngGi7gKZ9WjKdSoy9R8JcgOmjCMlDmLG20KhNo/i/Dc/Ah5GAvGfm8kfniV3AkR6fxN6eKwjDc6xrDgSfS48G5uGV6WzQt24YAVlLSK9BMwndzfHnePK1KFchFrL7O3ulB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mWJLis2oyEgPkJqyx0vYI8rjkVEzKc8eQavAJBYSpjMwM193Swt+yJyjvaGYWPnqExxKiNarpB2WSO7soCAZXhS1uEYHryrK47BH6W1dRiruqT0xpLih3MXiwU3VDwAAAA==';-/*** Core SQLite database client.* Provides low-level database operations and exposes repositories for domain-specific operations.@@ -400,21 +395,24 @@ export class SqliteClient implements IDatabaseClient {/*** Convert binary data to a base64 encoded image source.* @param bytes - Binary image data- * @returns Data URL for the image+ * @returns Data URL for the image, or null if no valid image data*/- public static imgSrcFromBytes(bytes: Uint8Array<ArrayBufferLike> | number[] | undefined): string {- if (bytes) {- try {- const logoBytes = this.toUint8Array(bytes);- const base64Logo = this.base64Encode(logoBytes);- const mimeType = this.detectMimeType(logoBytes);- return `data:${mimeType};base64,${base64Logo}`;- } catch (error) {- console.error('Error setting logo:', error);- return `data:image/x-icon;base64,${placeholderBase64}`;+ public static imgSrcFromBytes(bytes: Uint8Array<ArrayBufferLike> | number[] | undefined): string | null {+ if (!bytes || (Array.isArray(bytes) && bytes.length === 0) || (bytes instanceof Uint8Array && bytes.length === 0)) {+ return null;+ }++ try {+ const logoBytes = this.toUint8Array(bytes);+ const base64Logo = this.base64Encode(logoBytes);+ if (!base64Logo) {+ return null;}- } else {- return `data:image/x-icon;base64,${placeholderBase64}`;+ const mimeType = this.detectMimeType(logoBytes);+ return `data:${mimeType};base64,${base64Logo}`;+ } catch (error) {+ console.error('Error setting logo:', error);+ return null;}}