From 17899ae137bbb109e5ca8c843ca180dd0e4f9d28 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 6 Aug 2026 00:39:26 +0200 Subject: [PATCH] =?UTF-8?q?Rework=20Identit=C3=A4ten=20dialog=20to=20match?= =?UTF-8?q?=20the=20native=20client's=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old dialog was a flat list with an inline rename field and a radio button per row - visually and structurally nothing like the native myTeamSpeak-style Identitäten window. Reworked to the same list + detail panel layout: pick an identity on the left, edit its Name/Nickname/ Phonetischer Nickname on the right, see its Eindeutige ID (once known) and creation status, Standard/Löschen/Exportieren buttons per identity. Also added what was actually missing functionally, not just visually: - Import/Export: an identity's opaque tsclientlib blob can be downloaded as a JSON file and re-imported later (backup/transfer between browsers). - Per-identity nickname: each identity now remembers its own nickname (like native TS3), applied when switching identities in the connect dialog and saved back after a successful connect - previously there was only one global nickname shared by every identity. Deliberately left out of scope (documented inline in the component): myTeamSpeak cloud-synced identities (a whole separate account system this self-hosted client has no equivalent of) and the manual "Sicherheitsstufe erhöhen" button (tsclientlib already runs that proof-of-work step automatically during connect whenever a server demands a higher level, so a manual trigger wouldn't add functionality, only let you pre-compute it before connecting). Verified interactively in demo mode: dialog renders in the new layout, fields are all editable, Standard/Löschen/Export honor their expected enabled/disabled states. --- web/src/App.css | 45 +++++++-- web/src/App.tsx | 253 +++++++++++++++++++++++++++++++++++++++-------- web/src/i18n.tsx | 18 ++++ 3 files changed, 265 insertions(+), 51 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index 514df57..d436766 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -996,7 +996,19 @@ } .ts-identities-dialog { - width: 460px; + width: 520px; +} + +.ts-identities-body { + display: flex; + gap: 1rem; + align-items: flex-start; +} + +.ts-identities-list-label { + font-size: 11px; + color: var(--text-muted); + margin-bottom: 0.25rem; } .ts-identities-list { @@ -1005,32 +1017,45 @@ padding: 0; border: 1px solid var(--border-soft); border-radius: 3px; + width: 180px; max-height: 260px; overflow-y: auto; } -.ts-identities-item { - display: flex; - align-items: center; - gap: 0.5rem; - padding: 0.35rem 0.5rem; +.ts-identities-list li { border-bottom: 1px solid var(--border-soft); +} + +.ts-identities-list li:last-child { + border-bottom: none; +} + +.ts-identities-list-item { + display: block; + width: 100%; + padding: 0.35rem 0.5rem; font-size: 12px; } -.ts-identities-item-active { - background: var(--accent-soft, rgba(78, 161, 247, 0.15)); +.ts-identities-list-item-default { + font-weight: bold; } -.ts-identities-name { +.ts-identities-detail { flex: 1; min-width: 0; + display: flex; + flex-direction: column; + gap: 0.6rem; +} + +.ts-identities-readonly { + color: var(--text-muted); } .ts-identities-status { color: var(--text-muted); font-size: 11px; - white-space: nowrap; } .ts-log-level-row { diff --git a/web/src/App.tsx b/web/src/App.tsx index 424ebbe..0fcfb19 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -75,6 +75,10 @@ const ACTIVE_IDENTITY_KEY = "webspeak3:active-identity"; interface Identity { id: string; name: string; + /** Per-identity nickname/phonetic nickname, like the native client - selecting + * an identity in the connect dialog fills these in. Empty until first set. */ + nickname: string; + phoneticName: string; /** Opaque tsclientlib identity blob - null until the first successful connect generates one. */ blob: string | null; } @@ -85,8 +89,11 @@ interface Identity { (function ensureIdentitiesSeeded() { if (localStorage.getItem(IDENTITIES_KEY) !== null) return; const legacyBlob = localStorage.getItem(IDENTITY_KEY); + const legacyNickname = localStorage.getItem(LAST_NICKNAME_KEY) ?? ""; const id = crypto.randomUUID(); - const identities: Identity[] = [{ id, name: "Standard", blob: legacyBlob }]; + const identities: Identity[] = [ + { id, name: "Standard", nickname: legacyNickname, phoneticName: "", blob: legacyBlob }, + ]; localStorage.setItem(IDENTITIES_KEY, JSON.stringify(identities)); localStorage.setItem(ACTIVE_IDENTITY_KEY, id); localStorage.removeItem(IDENTITY_KEY); @@ -95,12 +102,22 @@ interface Identity { function loadIdentities(): Identity[] { try { const raw = localStorage.getItem(IDENTITIES_KEY); - const parsed = raw ? (JSON.parse(raw) as Identity[]) : []; - if (parsed.length > 0) return parsed; + const parsed = raw ? (JSON.parse(raw) as Partial[]) : []; + if (parsed.length > 0) { + // Backfill fields older saves (before per-identity nickname/phonetic + // name existed) don't have. + return parsed.map((i) => ({ + id: i.id ?? crypto.randomUUID(), + name: i.name ?? "Standard", + nickname: i.nickname ?? "", + phoneticName: i.phoneticName ?? "", + blob: i.blob ?? null, + })); + } } catch { // fall through } - return [{ id: crypto.randomUUID(), name: "Standard", blob: null }]; + return [{ id: crypto.randomUUID(), name: "Standard", nickname: "", phoneticName: "", blob: null }]; } const FAVORITES_KEY = "webspeak3:favorites"; @@ -2730,25 +2747,50 @@ function ServerConnectionInfoDialog({ ); } +/** Mirrors the native client's "Identitäten" window: a list on the left plus + * a detail panel on the right (Name/Nickname/Phonetischer Nickname/ + * Eindeutige ID), rather than the old flat list-with-inline-rename layout. + * The native window also has a myTeamSpeak-synced identity list and a + * "Sicherheitsstufe erhöhen" button - both deliberately out of scope here: + * the former needs a whole separate cloud-account system this self-hosted + * client doesn't have, and the latter (tsclientlib's proof-of-work identity + * level increase) already runs automatically during connect whenever a + * server demands a higher level, so there's nothing a manual button would + * add beyond letting you pre-compute it before connecting. */ function IdentitiesDialog({ identities, activeId, + ownUid, onActivate, onAdd, onRename, + onNicknameChange, + onPhoneticChange, onDelete, + onExport, + onImport, onClose, }: { identities: Identity[]; activeId: string | null; + /** The connected own client's unique ID, if currently connected with the + * active identity - shown as that identity's "Eindeutige ID". */ + ownUid: string | null; onActivate: (id: string) => void; onAdd: () => void; onRename: (id: string, name: string) => void; + onNicknameChange: (id: string, value: string) => void; + onPhoneticChange: (id: string, value: string) => void; onDelete: (id: string) => void; + onExport: (id: string) => void; + onImport: (file: File) => void; onClose: () => void; }) { const t = useT(); const backdrop = useBackdropDismiss(onClose); + const importInputRef = useRef(null); + const [selectedId, setSelectedId] = useState(activeId ?? identities[0]?.id ?? null); + const selected = identities.find((i) => i.id === selectedId) ?? identities[0] ?? null; return (
@@ -2759,41 +2801,102 @@ function IdentitiesDialog({ ✕
-
-
    - {identities.map((identity) => ( -
  • - onActivate(identity.id)} - title={t("identities.activate")} - /> - onRename(identity.id, e.target.value)} - /> - - {identity.blob ? t("identities.generated") : t("identities.pending")} - - -
  • - ))} -
+
+
+
{t("identities.listLabel")}
+
    + {identities.map((identity) => ( +
  • + +
  • + ))} +
+
+
+ {selected && ( + <> + + + + +
+ {selected.blob ? t("identities.generated") : t("identities.pending")} +
+ + )} +
- +
+ + + { + const file = e.target.files?.[0]; + e.target.value = ""; + if (file) onImport(file); + }} + /> + {selected && ( + <> + + + + + )} +
@@ -4324,9 +4427,13 @@ function AppInner() { setConnected(true); localStorage.setItem(LAST_HOST_KEY, connectHost); localStorage.setItem(LAST_NICKNAME_KEY, connectNickname); - if (data.identity && connectIdentityId) { + if (connectIdentityId) { setIdentities((prev) => - prev.map((i) => (i.id === connectIdentityId ? { ...i, blob: data.identity } : i)) + prev.map((i) => + i.id === connectIdentityId + ? { ...i, blob: data.identity || i.blob, nickname: connectNickname } + : i + ) ); } setServerName(data.serverName); @@ -5178,8 +5285,24 @@ function AppInner() { setWhisperLists((prev) => prev.filter((list) => list.id !== id)); }; + /** Switching identities (in the connect dialog's picker) also switches the + * nickname field to that identity's own remembered nickname, like the + * native client - only when it actually has one saved, so a fresh + * identity doesn't blank out what the user already typed. */ + const handleActiveIdentityChange = (id: string) => { + setActiveIdentityId(id); + const identity = identities.find((i) => i.id === id); + if (identity?.nickname) setNickname(identity.nickname); + }; + const handleAddIdentity = () => { - const identity: Identity = { id: crypto.randomUUID(), name: t("identities.newName"), blob: null }; + const identity: Identity = { + id: crypto.randomUUID(), + name: t("identities.newName"), + nickname: "", + phoneticName: "", + blob: null, + }; setIdentities((prev) => [...prev, identity]); }; @@ -5187,6 +5310,15 @@ function AppInner() { setIdentities((prev) => prev.map((i) => (i.id === id ? { ...i, name } : i))); }; + const handleIdentityNicknameChange = (id: string, value: string) => { + setIdentities((prev) => prev.map((i) => (i.id === id ? { ...i, nickname: value } : i))); + if (id === activeIdentityId) setNickname(value); + }; + + const handleIdentityPhoneticChange = (id: string, value: string) => { + setIdentities((prev) => prev.map((i) => (i.id === id ? { ...i, phoneticName: value } : i))); + }; + const handleDeleteIdentity = (id: string) => { setIdentities((prev) => { if (prev.length <= 1) return prev; @@ -5196,6 +5328,40 @@ function AppInner() { }); }; + /** Downloads one identity's opaque tsclientlib blob as a JSON file - the + * same file this dialog's "Importieren" button reads back in, so it + * doubles as a backup/transfer mechanism between browsers or devices. */ + const handleExportIdentity = (id: string) => { + const identity = identities.find((i) => i.id === id); + if (!identity?.blob) return; + const blob = new Blob([identity.blob], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = `${identity.name.replace(/[^a-z0-9_-]+/gi, "_") || "identity"}.ts3identity.json`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + }; + + const handleImportIdentity = (file: File) => { + const reader = new FileReader(); + reader.onload = () => { + const text = (reader.result as string).trim(); + try { + JSON.parse(text); + } catch { + logClient("error", "Identitäten", `"${file.name}" ist keine gültige Identitätsdatei.`); + return; + } + const name = file.name.replace(/\.(ts3identity\.)?json$/i, "") || t("identities.newName"); + const identity: Identity = { id: crypto.randomUUID(), name, nickname: "", phoneticName: "", blob: text }; + setIdentities((prev) => [...prev, identity]); + }; + reader.readAsText(file); + }; + const handleShowClientConnectionInfo = (clientId: number, clientName: string) => { setClientConnectionInfoTarget({ id: clientId, name: clientName }); setClientConnectionInfo(null); @@ -6235,7 +6401,7 @@ function AppInner() { onServerPasswordChange={setServerPassword} onChannelPasswordChange={setChannelPassword} onDefaultChannelChange={setDefaultChannel} - onActiveIdentityChange={setActiveIdentityId} + onActiveIdentityChange={handleActiveIdentityChange} onToggleExpanded={() => setConnectDialogExpanded((v) => !v)} onConnect={handleConnect} onCancel={() => setConnectDialogOpen(false)} @@ -6295,10 +6461,15 @@ function AppInner() { setIdentitiesOpen(false)} /> )} diff --git a/web/src/i18n.tsx b/web/src/i18n.tsx index 04a76ec..caffb2f 100644 --- a/web/src/i18n.tsx +++ b/web/src/i18n.tsx @@ -134,6 +134,15 @@ const translations: Record> = { "identities.newName": "Neue Identität", "identities.generated": "Erstellt", "identities.pending": "Wird bei der nächsten Verbindung erstellt", + "identities.listLabel": "Lokale Identitäten", + "identities.name": "Identität Name:", + "identities.phoneticNickname": "Phonetischer Nickname:", + "identities.uniqueId": "Eindeutige ID:", + "identities.unknown": "Unbekannt", + "identities.setDefault": "Standard", + "identities.isDefault": "Aktuell als Standard verwendet", + "identities.export": "Exportieren", + "identities.import": "Importieren", "connectionInfo.clientTitle": "Verbindungsinformationen - {name}", "connectionInfo.serverTitle": "Serververbindungsinformationen", @@ -625,6 +634,15 @@ const translations: Record> = { "identities.newName": "New Identity", "identities.generated": "Generated", "identities.pending": "Will be generated on next connection", + "identities.listLabel": "Local Identities", + "identities.name": "Identity Name:", + "identities.phoneticNickname": "Phonetic Nickname:", + "identities.uniqueId": "Unique ID:", + "identities.unknown": "Unknown", + "identities.setDefault": "Set as Default", + "identities.isDefault": "Currently used as default", + "identities.export": "Export", + "identities.import": "Import", "connectionInfo.clientTitle": "Connection Info - {name}", "connectionInfo.serverTitle": "Server Connection Info",