- A picture download sent to the voice connection while it closes (or still queued when it ends) was dropped without an answer: its cache key stayed in flight and every later fetch of it, in any session, waited until the app restarted. The request now fails when dropped unanswered (ImageDownload), so the retries fetch it again. - Only top-level channels are spacers, as in TeamSpeak: a sub-channel named [cspacer…] keeps its name, its lock and its member count. Chat tabs, the voice headers and "In …" use the same title as the tree. - A banner covered its row's own background: our channel and the hovered row are tinted over the artwork again. A locked centred spacer shows its lock. - A picture that cannot be decoded is remembered as such instead of being read again on the UI thread at every refresh (every talking change); avatars and icons that arrive again are decoded again. - Cache::icon no longer opens and touches the file on every refresh of the server list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEpqsPES27Eacue91u3d2Q
370 lines
14 KiB
Plaintext
370 lines
14 KiB
Plaintext
// The server's sidebar: the server card, connect and observe, and the
|
|
// channel tree with its clients.
|
|
|
|
import { Theme } from "../theme.slint";
|
|
import { Icons } from "../icons.slint";
|
|
import { Bridge, TreeItem } from "../bridge.slint";
|
|
import { Nav } from "../nav.slint";
|
|
import { Icon, Button, ButtonKind, IconButton, Avatar, LiveBadge, Chip, SectionHeader, SpeakingBars, PopupMenu, MenuEntry, ListView, BannerPicture } from "../components/index.slint";
|
|
|
|
// The banner at the top of the sidebar: server name, counts, a menu.
|
|
export component ServerHeader inherits Rectangle {
|
|
height: 76px * Theme.font-scale;
|
|
border-radius: Theme.radius-lg;
|
|
clip: true;
|
|
background: Theme.surface-2;
|
|
accessible-role: AccessibleRole.groupbox;
|
|
accessible-label: Bridge.server-title;
|
|
if Bridge.server-banner.width > 0: BannerPicture {
|
|
source: Bridge.server-banner;
|
|
}
|
|
HorizontalLayout {
|
|
padding: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
Rectangle {
|
|
width: 42px;
|
|
height: 42px;
|
|
y: (parent.height - self.height) / 2;
|
|
if Bridge.server-icon.width > 0: Image {
|
|
width: 100%;
|
|
height: 100%;
|
|
source: Bridge.server-icon;
|
|
image-fit: contain;
|
|
accessible-role: AccessibleRole.none;
|
|
}
|
|
if Bridge.server-icon.width == 0: Icon {
|
|
source: Icons.server;
|
|
size: 32px;
|
|
tint: Theme.text-secondary;
|
|
x: (parent.width - self.width) / 2;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
alignment: center;
|
|
horizontal-stretch: 1;
|
|
spacing: 3px;
|
|
Text {
|
|
text: Bridge.server-title;
|
|
font-size: Theme.font-md;
|
|
font-weight: Theme.weight-semibold;
|
|
color: Theme.text;
|
|
overflow: elide;
|
|
}
|
|
HorizontalLayout {
|
|
spacing: Theme.space-2;
|
|
Rectangle {
|
|
width: 7px;
|
|
height: 7px;
|
|
y: (parent.height - self.height) / 2;
|
|
border-radius: 4px;
|
|
background: Bridge.voice-connected ? Theme.success : Bridge.observing ? Theme.info : Bridge.voice-connecting ? Theme.warning : Theme.offline;
|
|
}
|
|
Text {
|
|
text: Bridge.server-stats != "" ? Bridge.server-stats
|
|
: Bridge.voice-connecting ? @tr("Connecting…")
|
|
: Bridge.current-server >= 0 ? @tr("Not connected") : @tr("Add a server to start");
|
|
font-size: Theme.font-xs;
|
|
color: Bridge.server-banner.width > 0 ? Theme.text : Theme.text-secondary;
|
|
overflow: elide;
|
|
}
|
|
}
|
|
}
|
|
if Bridge.current-server >= 0: IconButton {
|
|
icon: Icons.chevron-down;
|
|
label: @tr("Server menu");
|
|
size: 24px;
|
|
icon-size: Theme.icon-sm;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { menu.show(self.x + self.width - 220px, self.y + self.height + 4px); }
|
|
}
|
|
}
|
|
menu := PopupMenu {
|
|
entries: [
|
|
{ text: @tr("Edit server"), icon: Icons.pencil, enabled: Bridge.current-server >= 0 },
|
|
{ text: Bridge.observing ? @tr("Stop observing") : @tr("Observe invisibly"), icon: Icons.eye, enabled: Bridge.can-observe },
|
|
{ text: @tr("Add server"), icon: Icons.plus, enabled: true, separator: true },
|
|
];
|
|
activated(i) => {
|
|
if i == 0 {
|
|
Nav.edit-server(Bridge.current-server);
|
|
} else if i == 1 {
|
|
Bridge.toggle-observe();
|
|
} else {
|
|
Nav.add-server();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Connect and observe while not connected.
|
|
export component ConnectActions inherits HorizontalLayout {
|
|
spacing: Theme.space-3;
|
|
Button {
|
|
horizontal-stretch: 1;
|
|
kind: ButtonKind.primary;
|
|
icon: Icons.log-in;
|
|
text: Bridge.voice-connecting ? @tr("Connecting…") : @tr("Connect");
|
|
enabled: Bridge.current-server >= 0 && !Bridge.voice-connecting;
|
|
clicked => { Bridge.connect-voice(); }
|
|
}
|
|
Button {
|
|
icon: Bridge.observing ? Icons.eye-off : Icons.eye;
|
|
text: Bridge.observing ? @tr("Stop observing") : @tr("Observe");
|
|
enabled: Bridge.can-observe;
|
|
checked: Bridge.observing;
|
|
clicked => { Bridge.toggle-observe(); }
|
|
}
|
|
}
|
|
|
|
// A server-provided icon in its own colours.
|
|
component RowIcon inherits VerticalLayout {
|
|
in property <image> source;
|
|
alignment: center;
|
|
Image {
|
|
width: 16px;
|
|
height: 16px;
|
|
source: root.source;
|
|
image-fit: contain;
|
|
accessible-role: AccessibleRole.none;
|
|
}
|
|
}
|
|
|
|
// One row of the tree: a channel or a client.
|
|
component TreeRow inherits Rectangle {
|
|
in property <TreeItem> item;
|
|
callback client-clicked(int);
|
|
property <length> indent: item.depth * 14px;
|
|
height: item.is-channel ? 34px * Theme.font-scale : 30px * Theme.font-scale;
|
|
clip: true;
|
|
border-radius: Theme.radius-md;
|
|
background: item.is-channel && item.own ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : transparent;
|
|
border-width: item.is-channel && item.own ? 1px : 0px;
|
|
border-color: Theme.accent;
|
|
accessible-role: AccessibleRole.list-item;
|
|
accessible-label: item.is-channel ? @tr("Channel {}", item.name) : item.name;
|
|
accessible-description: (item.talking ? @tr("talking") + " " : "") + (item.streaming ? @tr("streaming") + " " : "") + (item.muted ? @tr("microphone off") + " " : "") + (item.local-muted ? @tr("muted for you") : "");
|
|
accessible-action-default => {
|
|
if item.is-channel {
|
|
Bridge.open-channel-chat(item.id);
|
|
} else {
|
|
client-clicked(item.id);
|
|
}
|
|
}
|
|
// Artwork is clipped behind the same compact row as its title.
|
|
if item.is-channel && item.banner.width > 0: BannerPicture {
|
|
x: root.indent;
|
|
width: max(0px, root.width - root.indent);
|
|
y: 0;
|
|
source: item.banner;
|
|
}
|
|
// The artwork covers the row's own background: tint it as that would
|
|
// be for our channel and on hover, translucent so the picture shows.
|
|
if item.is-channel && item.banner.width > 0 && (item.own || area.has-hover): Rectangle {
|
|
x: root.indent;
|
|
width: max(0px, root.width - root.indent);
|
|
border-radius: root.border-radius;
|
|
background: item.own ? Theme.accent-soft.transparentize(0.35) : Theme.surface-3.transparentize(0.5);
|
|
}
|
|
area := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
double-clicked => {
|
|
if item.is-channel {
|
|
Bridge.join-channel(item.id);
|
|
}
|
|
}
|
|
clicked => {
|
|
if item.is-channel {
|
|
Bridge.open-channel-chat(item.id);
|
|
} else if !item.myself {
|
|
client-clicked(item.id);
|
|
}
|
|
}
|
|
}
|
|
if item.is-channel: HorizontalLayout {
|
|
height: 34px * Theme.font-scale;
|
|
padding-left: Theme.space-2 + root.indent;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-2;
|
|
if item.centered-spacer: Rectangle { width: 18px; }
|
|
if !item.centered-spacer && item.icon.width > 0: RowIcon {
|
|
source: item.icon;
|
|
}
|
|
if !item.centered-spacer && item.icon.width == 0: Icon {
|
|
source: item.locked ? Icons.lock : Icons.volume-2;
|
|
size: 18px;
|
|
tint: item.banner.width > 0 || item.own ? Theme.text : Theme.icon;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: item.name;
|
|
horizontal-alignment: item.centered-spacer ? center : left;
|
|
// Full contrast over a banner.
|
|
color: item.own || item.banner.width > 0 ? Theme.text : Theme.text-secondary;
|
|
font-weight: item.own || item.banner.width > 0 ? Theme.weight-semibold : Theme.weight-medium;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 1;
|
|
overflow: elide;
|
|
}
|
|
// At the end where the start shows the channel's icon, or nothing
|
|
// (a centred spacer).
|
|
if item.locked && (item.icon.width > 0 || item.centered-spacer): Icon {
|
|
source: Icons.lock;
|
|
size: 14px;
|
|
tint: item.banner.width > 0 ? Theme.text : Theme.icon;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
if !item.centered-spacer && (item.members > 0 || item.max-members >= 0): HorizontalLayout {
|
|
spacing: 3px;
|
|
if item.own: Icon {
|
|
source: Icons.users;
|
|
size: 14px;
|
|
tint: Theme.text-secondary;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: item.max-members >= 0 ? item.members + "/" + item.max-members : item.members;
|
|
color: item.own || item.banner.width > 0 ? Theme.text : Theme.text-muted;
|
|
font-size: Theme.font-sm;
|
|
vertical-alignment: center;
|
|
}
|
|
}
|
|
Rectangle {
|
|
width: 18px;
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: item.collapsed ? @tr("Expand") : @tr("Collapse");
|
|
accessible-action-default => { Bridge.toggle-collapse(item.id); }
|
|
Icon {
|
|
source: item.collapsed ? Icons.chevron-right : Icons.chevron-down;
|
|
size: 14px;
|
|
tint: item.banner.width > 0 ? Theme.text : Theme.text-muted;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
TouchArea {
|
|
clicked => { Bridge.toggle-collapse(item.id); }
|
|
}
|
|
}
|
|
}
|
|
if !item.is-channel: HorizontalLayout {
|
|
padding-left: Theme.space-2 + root.indent + 12px;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
VerticalLayout {
|
|
alignment: center;
|
|
Avatar {
|
|
size: 22px;
|
|
initials: item.initials;
|
|
tint: item.tint;
|
|
image: item.avatar;
|
|
speaking: item.talking;
|
|
label: item.name;
|
|
}
|
|
}
|
|
Text {
|
|
text: item.name;
|
|
color: item.away ? Theme.text-muted : item.myself ? Theme.accent-text : Theme.text-secondary;
|
|
font-weight: item.myself ? Theme.weight-semibold : Theme.weight-regular;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 1;
|
|
overflow: elide;
|
|
}
|
|
if item.talking: VerticalLayout {
|
|
alignment: center;
|
|
SpeakingBars { }
|
|
}
|
|
// A click on someone's LIVE mark watches their stream.
|
|
if item.streaming: VerticalLayout {
|
|
alignment: center;
|
|
LiveBadge {
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: item.myself ? @tr("Your stream") : @tr("Watch {}'s stream", item.name);
|
|
accessible-action-default => {
|
|
if !item.myself {
|
|
Bridge.watch-client(item.id);
|
|
}
|
|
}
|
|
TouchArea {
|
|
mouse-cursor: item.myself ? MouseCursor.default : MouseCursor.pointer;
|
|
clicked => {
|
|
if !item.myself {
|
|
Bridge.watch-client(item.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if item.local-muted: Icon {
|
|
source: Icons.volume-x;
|
|
size: 14px;
|
|
tint: Theme.warning;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("muted for you");
|
|
}
|
|
if !item.local-muted && item.local-volume != 100: Text {
|
|
text: @tr("{}%", item.local-volume);
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-xs;
|
|
vertical-alignment: center;
|
|
}
|
|
if item.muted: Icon {
|
|
source: Icons.mic-off;
|
|
size: 14px;
|
|
tint: Theme.danger;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("mic off");
|
|
}
|
|
if item.sound-off: Icon {
|
|
source: Icons.headphone-off;
|
|
size: 14px;
|
|
tint: Theme.danger;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("sound off");
|
|
}
|
|
if item.away: Text {
|
|
text: @tr("away");
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-xs;
|
|
vertical-alignment: center;
|
|
}
|
|
// Group and client icons.
|
|
if item.icon.width > 0: RowIcon {
|
|
source: item.icon;
|
|
}
|
|
if item.icon-2.width > 0: RowIcon {
|
|
source: item.icon-2;
|
|
}
|
|
if item.icon-3.width > 0: RowIcon {
|
|
source: item.icon-3;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Channels and the clients in them. Click a channel for its chat,
|
|
// double-click to join; click a client for its volume.
|
|
export component ChannelTree inherits VerticalLayout {
|
|
spacing: Theme.space-2;
|
|
SectionHeader {
|
|
text: @tr("Channels");
|
|
icon: Icons.volume-2;
|
|
small: true;
|
|
}
|
|
if Bridge.tree.length == 0: Text {
|
|
text: Bridge.current-server < 0 ? @tr("No server yet.") : @tr("Connect or observe to see the channels.");
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-sm;
|
|
wrap: word-wrap;
|
|
}
|
|
ListView {
|
|
vertical-stretch: 1;
|
|
accessible-role: AccessibleRole.list;
|
|
accessible-label: @tr("Channels and clients");
|
|
for row in Bridge.tree: TreeRow {
|
|
item: row;
|
|
client-clicked(id) => { Nav.open-client(id); }
|
|
}
|
|
}
|
|
}
|