From a300daedeb723206a122d0a17e631d686bc279ec Mon Sep 17 00:00:00 2001 From: Moepchi Date: Tue, 4 Aug 2026 19:47:20 +0200 Subject: [PATCH] =?UTF-8?q?Add=20Identit=C3=A4ten=20(identity)=20managemen?= =?UTF-8?q?t=20dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the single flat identity key with a list of named identities you can add, rename, delete, and switch between (each keeps its own tsclientlib identity blob, generated lazily on first connect). The Connect dialog's identity dropdown, previously a disabled "Standard" placeholder, now reflects and can switch the active one too. Existing users' single stored identity migrates automatically into the new list. Co-Authored-By: Claude Sonnet 5 --- web/src/App.css | 38 ++++++++++ web/src/App.tsx | 186 +++++++++++++++++++++++++++++++++++++++++++++-- web/src/i18n.tsx | 16 ++++ 3 files changed, 235 insertions(+), 5 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index ab68358..f05fc96 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -959,6 +959,44 @@ color: var(--text-muted); } +.ts-identities-dialog { + width: 460px; +} + +.ts-identities-list { + list-style: none; + margin: 0; + padding: 0; + border: 1px solid var(--border-soft); + border-radius: 3px; + max-height: 260px; + overflow-y: auto; +} + +.ts-identities-item { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.35rem 0.5rem; + border-bottom: 1px solid var(--border-soft); + font-size: 12px; +} + +.ts-identities-item-active { + background: var(--accent-soft, rgba(78, 161, 247, 0.15)); +} + +.ts-identities-name { + flex: 1; + min-width: 0; +} + +.ts-identities-status { + color: var(--text-muted); + font-size: 11px; + white-space: nowrap; +} + .ts-log-level-row { flex-wrap: wrap; } diff --git a/web/src/App.tsx b/web/src/App.tsx index e11d879..5fece7e 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -69,6 +69,40 @@ const LAST_NICKNAME_KEY = "webspeak3:last-nickname"; /** Identity persisted across sessions so the server sees the same client UID * each time, instead of a fresh one being generated per connection. */ const IDENTITY_KEY = "webspeak3:identity"; +const IDENTITIES_KEY = "webspeak3:identities"; +const ACTIVE_IDENTITY_KEY = "webspeak3:active-identity"; + +interface Identity { + id: string; + name: string; + /** Opaque tsclientlib identity blob - null until the first successful connect generates one. */ + blob: string | null; +} + +// One-time migration from the old single flat identity key to a list of named +// identities (so users can maintain more than one persona), and to seed a +// default entry for users who never had one either. Runs once at module load. +(function ensureIdentitiesSeeded() { + if (localStorage.getItem(IDENTITIES_KEY) !== null) return; + const legacyBlob = localStorage.getItem(IDENTITY_KEY); + const id = crypto.randomUUID(); + const identities: Identity[] = [{ id, name: "Standard", blob: legacyBlob }]; + localStorage.setItem(IDENTITIES_KEY, JSON.stringify(identities)); + localStorage.setItem(ACTIVE_IDENTITY_KEY, id); + localStorage.removeItem(IDENTITY_KEY); +})(); + +function loadIdentities(): Identity[] { + try { + const raw = localStorage.getItem(IDENTITIES_KEY); + const parsed = raw ? (JSON.parse(raw) as Identity[]) : []; + if (parsed.length > 0) return parsed; + } catch { + // fall through + } + return [{ id: crypto.randomUUID(), name: "Standard", blob: null }]; +} + const FAVORITES_KEY = "webspeak3:favorites"; const INPUT_DEVICE_KEY = "webspeak3:input-device"; const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume"; @@ -519,11 +553,14 @@ function ConnectDialog({ defaultChannel, expanded, connecting, + identities, + activeIdentityId, onHostChange, onNicknameChange, onServerPasswordChange, onChannelPasswordChange, onDefaultChannelChange, + onActiveIdentityChange, onToggleExpanded, onConnect, onCancel, @@ -535,11 +572,14 @@ function ConnectDialog({ defaultChannel: string; expanded: boolean; connecting: boolean; + identities: Identity[]; + activeIdentityId: string | null; onHostChange: (v: string) => void; onNicknameChange: (v: string) => void; onServerPasswordChange: (v: string) => void; onChannelPasswordChange: (v: string) => void; onDefaultChannelChange: (v: string) => void; + onActiveIdentityChange: (id: string) => void; onToggleExpanded: () => void; onConnect: () => void; onCancel: () => void; @@ -583,8 +623,12 @@ function ConnectDialog({