From 6bc3dca567708a1a27aca08f90d395274c40b540 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Mon, 10 Aug 2026 21:23:54 +0200 Subject: [PATCH] Add colored-letter badges for TS3 built-in default group icons; only fetch real custom icon files --- connector/src/main.rs | 12 ++--------- web/src/App.css | 14 ++++++++++++ web/src/App.tsx | 50 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/connector/src/main.rs b/connector/src/main.rs index 295740f..032bf9b 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -1542,14 +1542,12 @@ async fn run(args: Args) -> Result<()> { let mut parts = rest.trim().splitn(2, ' '); let cid_str = parts.next().unwrap_or(""); let path = parts.next().unwrap_or("").trim(); - eprintln!("DEBUG ftdownload requested: cid={cid_str} path={path}"); match cid_str.parse::() { Ok(cid) => match con.download_file(ChannelId(cid), path, None, None) { Ok(handle) => { - eprintln!("DEBUG ftdownload handle={} for {path}", handle.0); pending_downloads.insert(handle.0, (cid, path.to_string())); } - Err(e) => eprintln!("DEBUG ftdownload failed for {path}: {e}"), + Err(e) => emit(&Event::Error { message: format!("Download failed: {e}") }), }, Err(_) => emit(&Event::Error { message: format!("Invalid channel id: {cid_str}") }), } @@ -1976,7 +1974,6 @@ async fn run(args: Args) -> Result<()> { .map(|g| GroupEntry { id: g.id.0, name: g.name.clone(), icon_id: g.icon.0 }) .collect(); entries.sort_by_key(|g| g.id); - eprintln!("DEBUG channel groups: {:?}", entries.iter().map(|g| (g.id, &g.name, g.icon_id)).collect::>()); emit(&Event::ChannelGroupList { entries }); pending_channel_group_list = false; } else if label == "Server group list" && pending_server_group_list { @@ -1987,7 +1984,6 @@ async fn run(args: Args) -> Result<()> { .map(|g| GroupEntry { id: g.id.0, name: g.name.clone(), icon_id: g.icon.0 }) .collect(); entries.sort_by_key(|g| g.id); - eprintln!("DEBUG server groups: {:?}", entries.iter().map(|g| (g.id, &g.name, g.icon_id)).collect::>()); emit(&Event::ServerGroupList { entries }); pending_server_group_list = false; } else if label == "Permission list" && pending_permission_list { @@ -2289,14 +2285,10 @@ async fn run(args: Args) -> Result<()> { let mut buf = Vec::new(); match stream.read_to_end(&mut buf).await { Ok(_) => { - eprintln!("DEBUG ftdownload done: cid={cid} path={path} bytes={}", buf.len()); let data = base64::engine::general_purpose::STANDARD.encode(&buf); emit(&Event::FileDownloadData { cid, path, data }); } - Err(e) => { - eprintln!("DEBUG ftdownload read error: cid={cid} path={path}: {e}"); - emit(&Event::Error { message: format!("Download failed: {e}") }); - } + Err(e) => emit(&Event::Error { message: format!("Download failed: {e}") }), } }); } diff --git a/web/src/App.css b/web/src/App.css index 9089615..757e278 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -567,6 +567,20 @@ flex-shrink: 0; } +.ts-group-badge { + display: inline-flex; + align-items: center; + justify-content: center; + width: 14px; + height: 14px; + border-radius: 50%; + flex-shrink: 0; + font-size: 9px; + font-weight: 700; + line-height: 1; + color: #fff; +} + .ts-poke-button { margin-left: auto; background: transparent; diff --git a/web/src/App.tsx b/web/src/App.tsx index d15ef35..75e9d82 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -518,11 +518,11 @@ function ChannelTree({ const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order); if (children.length === 0) return null; - const groupIconIds = (client: ClientInfo): number[] => + const clientGroupBadges = (client: ClientInfo): GroupEntry[] => serverGroups ? client.serverGroups - .map((gid) => serverGroups.find((g) => g.id === gid)?.iconId ?? 0) - .filter((iconId) => iconId !== 0) + .map((gid) => serverGroups.find((g) => g.id === gid)) + .filter((g): g is GroupEntry => !!g && g.iconId !== 0) : []; return ( @@ -563,11 +563,25 @@ function ChannelTree({ )} - {groupIconIds(c).map((iconId) => { - const base64 = groupIconImages[`/icon_${iconId}`]; - return base64 ? ( - - ) : null; + {clientGroupBadges(c).map((g) => { + if (g.iconId >= CUSTOM_ICON_ID_THRESHOLD) { + const base64 = groupIconImages[`/icon_${g.iconId}`]; + if (base64) { + return ( + + ); + } + } + return ( + + {g.name.trim().charAt(0).toUpperCase() || "?"} + + ); })} {c.id !== ownClientId && ( @@ -1912,6 +1926,22 @@ function iconDataUrl(base64: string): string { return `data:${sniffImageMime(atob(base64))};base64,${base64}`; } +// IDs below this are TeamSpeak's built-in default group icons - they ship +// inside the official client and were never uploaded to the server's icon +// filebase, so downloadFile() for them just hangs forever (nothing to send +// back). We don't have those graphics to embed, so those get a generic +// colored-letter badge instead; only real custom uploads (id >= threshold) +// are fetched as actual images. +const CUSTOM_ICON_ID_THRESHOLD = 1000; + +/** Deterministic color for a group's letter badge - same icon id always + * produces the same hue, so a group looks consistent across the tree + * without needing the real (unavailable) TeamSpeak icon graphics. */ +function groupBadgeColor(iconId: number): string { + const hue = (iconId * 47) % 360; + return `hsl(${hue}, 55%, 45%)`; +} + /** The icon repository lives under TS3's special "channel 0" - not a real, * selectable channel, just the server-wide filebase icons are stored in. * Icon files are always named "icon_", where is what a server/ @@ -4940,7 +4970,9 @@ function AppInner() { if (!serverGroups) return; const iconById = new Map(serverGroups.map((g) => [g.id, g.iconId])); const wantedIconIds = new Set( - clients.flatMap((c) => c.serverGroups.map((gid) => iconById.get(gid) ?? 0)).filter((id) => id !== 0) + clients + .flatMap((c) => c.serverGroups.map((gid) => iconById.get(gid) ?? 0)) + .filter((id) => id >= CUSTOM_ICON_ID_THRESHOLD) ); for (const iconId of wantedIconIds) { const path = `/icon_${iconId}`;