mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Add colored-letter badges for TS3 built-in default group icons; only fetch real custom icon files
This commit is contained in:
1 parent
0a1163d4f9
commit
6bc3dca567
3 files changed
+57
-19
No files matched your search
+2
-10
@@ -1542,14 +1542,12 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
let mut parts = rest.trim().splitn(2, ' ');
|
let mut parts = rest.trim().splitn(2, ' ');
|
||||||
let cid_str = parts.next().unwrap_or("");
|
let cid_str = parts.next().unwrap_or("");
|
||||||
let path = parts.next().unwrap_or("").trim();
|
let path = parts.next().unwrap_or("").trim();
|
||||||
eprintln!("DEBUG ftdownload requested: cid={cid_str} path={path}");
|
|
||||||
match cid_str.parse::<u64>() {
|
match cid_str.parse::<u64>() {
|
||||||
Ok(cid) => match con.download_file(ChannelId(cid), path, None, None) {
|
Ok(cid) => match con.download_file(ChannelId(cid), path, None, None) {
|
||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
eprintln!("DEBUG ftdownload handle={} for {path}", handle.0);
|
|
||||||
pending_downloads.insert(handle.0, (cid, path.to_string()));
|
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}") }),
|
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 })
|
.map(|g| GroupEntry { id: g.id.0, name: g.name.clone(), icon_id: g.icon.0 })
|
||||||
.collect();
|
.collect();
|
||||||
entries.sort_by_key(|g| g.id);
|
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 });
|
emit(&Event::ChannelGroupList { entries });
|
||||||
pending_channel_group_list = false;
|
pending_channel_group_list = false;
|
||||||
} else if label == "Server group list" && pending_server_group_list {
|
} 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 })
|
.map(|g| GroupEntry { id: g.id.0, name: g.name.clone(), icon_id: g.icon.0 })
|
||||||
.collect();
|
.collect();
|
||||||
entries.sort_by_key(|g| g.id);
|
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 });
|
emit(&Event::ServerGroupList { entries });
|
||||||
pending_server_group_list = false;
|
pending_server_group_list = false;
|
||||||
} else if label == "Permission list" && pending_permission_list {
|
} else if label == "Permission list" && pending_permission_list {
|
||||||
@@ -2289,14 +2285,10 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
match stream.read_to_end(&mut buf).await {
|
match stream.read_to_end(&mut buf).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
eprintln!("DEBUG ftdownload done: cid={cid} path={path} bytes={}", buf.len());
|
|
||||||
let data = base64::engine::general_purpose::STANDARD.encode(&buf);
|
let data = base64::engine::general_purpose::STANDARD.encode(&buf);
|
||||||
emit(&Event::FileDownloadData { cid, path, data });
|
emit(&Event::FileDownloadData { cid, path, data });
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => emit(&Event::Error { message: format!("Download failed: {e}") }),
|
||||||
eprintln!("DEBUG ftdownload read error: cid={cid} path={path}: {e}");
|
|
||||||
emit(&Event::Error { message: format!("Download failed: {e}") });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -567,6 +567,20 @@
|
|||||||
flex-shrink: 0;
|
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 {
|
.ts-poke-button {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|||||||
+41
-9
@@ -518,11 +518,11 @@ function ChannelTree({
|
|||||||
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
||||||
if (children.length === 0) return null;
|
if (children.length === 0) return null;
|
||||||
|
|
||||||
const groupIconIds = (client: ClientInfo): number[] =>
|
const clientGroupBadges = (client: ClientInfo): GroupEntry[] =>
|
||||||
serverGroups
|
serverGroups
|
||||||
? client.serverGroups
|
? client.serverGroups
|
||||||
.map((gid) => serverGroups.find((g) => g.id === gid)?.iconId ?? 0)
|
.map((gid) => serverGroups.find((g) => g.id === gid))
|
||||||
.filter((iconId) => iconId !== 0)
|
.filter((g): g is GroupEntry => !!g && g.iconId !== 0)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -563,11 +563,25 @@ function ChannelTree({
|
|||||||
)}
|
)}
|
||||||
<span className="ts-client-icons">
|
<span className="ts-client-icons">
|
||||||
<ClientStatusIcons client={c} />
|
<ClientStatusIcons client={c} />
|
||||||
{groupIconIds(c).map((iconId) => {
|
{clientGroupBadges(c).map((g) => {
|
||||||
const base64 = groupIconImages[`/icon_${iconId}`];
|
if (g.iconId >= CUSTOM_ICON_ID_THRESHOLD) {
|
||||||
return base64 ? (
|
const base64 = groupIconImages[`/icon_${g.iconId}`];
|
||||||
<img key={iconId} className="ts-group-icon" src={iconDataUrl(base64)} alt="" />
|
if (base64) {
|
||||||
) : null;
|
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>
|
</span>
|
||||||
{c.id !== ownClientId && (
|
{c.id !== ownClientId && (
|
||||||
@@ -1912,6 +1926,22 @@ function iconDataUrl(base64: string): string {
|
|||||||
return `data:${sniffImageMime(atob(base64))};base64,${base64}`;
|
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,
|
/** The icon repository lives under TS3's special "channel 0" - not a real,
|
||||||
* selectable channel, just the server-wide filebase icons are stored in.
|
* selectable channel, just the server-wide filebase icons are stored in.
|
||||||
* Icon files are always named "icon_<id>", where <id> is what a server/
|
* Icon files are always named "icon_<id>", where <id> is what a server/
|
||||||
@@ -4940,7 +4970,9 @@ function AppInner() {
|
|||||||
if (!serverGroups) return;
|
if (!serverGroups) return;
|
||||||
const iconById = new Map(serverGroups.map((g) => [g.id, g.iconId]));
|
const iconById = new Map(serverGroups.map((g) => [g.id, g.iconId]));
|
||||||
const wantedIconIds = new Set(
|
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) {
|
for (const iconId of wantedIconIds) {
|
||||||
const path = `/icon_${iconId}`;
|
const path = `/icon_${iconId}`;
|
||||||
|
|||||||
Reference in new issue
Block a user