Add colored-letter badges for TS3 built-in default group icons; only fetch real custom icon files

This commit is contained in:
Moepchi committed 2026-08-10 21:23:54 +02:00
1 parent 0a1163d4f9
commit 6bc3dca567
3 files changed
+57 -19

No files matched your search

+2 -10
View File
@@ -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::<u64>() {
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::<Vec<_>>());
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::<Vec<_>>());
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}") }),
}
});
}
+14
View File
@@ -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;
+41 -9
View File
@@ -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({
)}
<span className="ts-client-icons">
<ClientStatusIcons client={c} />
{groupIconIds(c).map((iconId) => {
const base64 = groupIconImages[`/icon_${iconId}`];
return base64 ? (
<img key={iconId} className="ts-group-icon" src={iconDataUrl(base64)} alt="" />
) : null;
{clientGroupBadges(c).map((g) => {
if (g.iconId >= CUSTOM_ICON_ID_THRESHOLD) {
const base64 = groupIconImages[`/icon_${g.iconId}`];
if (base64) {
return (
<img key={g.id} className="ts-group-icon" src={iconDataUrl(base64)} alt="" title={g.name} />
);
}
}
return (
<span
key={g.id}
className="ts-group-badge"
style={{ background: groupBadgeColor(g.iconId) }}
title={g.name}
>
{g.name.trim().charAt(0).toUpperCase() || "?"}
</span>
);
})}
</span>
{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_<id>", where <id> 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}`;