Files
VoelinClient/crates/tsc-ui/ui/app.slint
T
Claude afe37b23a5 ci: allow Slint royalty-free license in cargo-deny, fix Slint binding loop
cargo-deny rejected Slint's license expression (GPL-3.0-only OR
LicenseRef-Slint-Royalty-free-2.0 OR ...) and ksni's Unlicense. We use Slint
under the royalty-free license, whose attribution is in the About page.

The main window's `narrow` flag was bound to its own width and panes bound
their width to the parent, which Slint reports as a binding loop. The flag is
now set from a change handler and panes use stretch/min/max widths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-25 19:21:56 +00:00

538 lines
18 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Button, LineEdit, ListView, ComboBox, AboutSlint, VerticalBox, HorizontalBox, ScrollView } from "std-widgets.slint";
export struct ServerItem {
id: int,
name: string,
address: string,
// "offline", "connecting", "observing" or "connected"
status: string,
}
export struct TreeItem {
is-channel: bool,
depth: int,
id: int,
name: string,
own: bool,
talking: bool,
muted: bool,
sound-off: bool,
away: bool,
streaming: bool,
locked: bool,
collapsed: bool,
}
export struct ChatTab {
title: string,
// 0 = server chat, 1 = channel chat
kind: int,
id: int,
unread: int,
}
export struct ChatLine {
author: string,
text: string,
time: string,
relayed: bool,
}
export struct BookmarkForm {
id: int,
name: string,
address: string,
nickname: string,
server-password: string,
gateway-url: string,
query-transport: string,
query-addr: string,
query-user: string,
query-password: string,
}
export global Bridge {
in property <[ServerItem]> servers;
in-out property <int> current-server: -1;
in property <[TreeItem]> tree;
in property <[ChatTab]> tabs;
in-out property <int> current-tab: 0;
in property <[ChatLine]> messages;
in property <string> status-text;
in property <string> server-title: "No server selected";
in property <bool> voice-connected;
in property <bool> voice-connecting;
in property <bool> observing;
in property <bool> can-observe;
in property <bool> input-muted;
in property <bool> output-muted;
in property <bool> transmitting;
in property <string> presence-source;
callback select-server(int);
callback connect-voice();
callback disconnect-voice();
callback toggle-observe();
callback join-channel(int);
callback open-channel-chat(int);
callback toggle-collapse(int);
callback select-tab(int);
callback close-tab(int);
callback send-message(string);
callback set-input-muted(bool);
callback set-output-muted(bool);
callback push-to-talk(bool);
callback edit-bookmark(int) -> BookmarkForm;
callback save-bookmark(BookmarkForm);
callback delete-bookmark(int);
}
component StatusDot inherits Rectangle {
in property <string> status;
width: 10px;
height: 10px;
border-radius: 5px;
background: status == "connected" ? #3fb950 : status == "observing" ? #58a6ff : status == "connecting" ? #d29922 : #6e7681;
}
component Field inherits HorizontalLayout {
in property <string> label;
in-out property <string> value;
in property <string> placeholder;
in property <InputType> input-type: InputType.text;
spacing: 8px;
Text {
text: label;
width: 130px;
vertical-alignment: center;
}
LineEdit {
text <=> value;
placeholder-text: placeholder;
input-type: input-type;
}
}
component BookmarkEditor inherits Rectangle {
in-out property <BookmarkForm> form;
callback done();
background: #000000a0;
TouchArea { }
Rectangle {
width: min(parent.width - 32px, 520px);
height: min(parent.height - 32px, 520px);
background: #1f2328;
border-radius: 8px;
VerticalBox {
Text {
text: form.id < 0 ? "Add server" : "Edit server";
font-size: 18px;
font-weight: 700;
}
ScrollView {
VerticalLayout {
spacing: 6px;
Field { label: "Name"; value <=> form.name; placeholder: "My server"; }
Field { label: "Address"; value <=> form.address; placeholder: "ts.example.org:9987"; }
Field { label: "Nickname"; value <=> form.nickname; }
Field { label: "Server password"; value <=> form.server-password; input-type: InputType.password; }
Text {
text: "Invisible presence and chat without joining (optional)";
font-weight: 600;
}
Field { label: "Gateway URL"; value <=> form.gateway-url; placeholder: "wss://gw.example.org/v1"; }
HorizontalLayout {
spacing: 8px;
Text {
text: "Query transport";
width: 130px;
vertical-alignment: center;
}
ComboBox {
model: ["none", "ssh", "raw", "http"];
current-value <=> form.query-transport;
}
}
Field { label: "Query address"; value <=> form.query-addr; placeholder: "ts.example.org:10022"; }
Field { label: "Query login"; value <=> form.query-user; }
Field { label: "Query password"; value <=> form.query-password; input-type: InputType.password; }
}
}
HorizontalLayout {
alignment: end;
spacing: 8px;
if form.id >= 0: Button {
text: "Delete";
clicked => {
Bridge.delete-bookmark(form.id);
done();
}
}
Button {
text: "Cancel";
clicked => { done(); }
}
Button {
text: "Save";
primary: true;
enabled: form.address != "" && form.nickname != "";
clicked => {
Bridge.save-bookmark(form);
done();
}
}
}
}
}
}
component ServerList inherits Rectangle {
callback add();
callback edit(int);
background: #161b22;
VerticalBox {
HorizontalLayout {
Text {
text: "Servers";
font-weight: 700;
vertical-alignment: center;
}
Button {
text: "+";
width: 32px;
clicked => { add(); }
}
}
ListView {
for server[i] in Bridge.servers: Rectangle {
height: 48px;
border-radius: 6px;
background: Bridge.current-server == server.id ? #30363d : area.has-hover ? #21262d : transparent;
area := TouchArea {
clicked => { Bridge.select-server(server.id); }
double-clicked => { edit(server.id); }
}
HorizontalLayout {
padding: 6px;
spacing: 8px;
StatusDot {
status: server.status;
y: (parent.height - self.height) / 2;
}
VerticalLayout {
Text {
text: server.name;
font-weight: 600;
overflow: elide;
}
Text {
text: server.address;
font-size: 11px;
color: #8b949e;
overflow: elide;
}
}
}
}
}
}
}
component ChannelTree inherits Rectangle {
background: #0d1117;
ListView {
for row in Bridge.tree: Rectangle {
height: 26px;
background: row-area.has-hover ? #161b22 : transparent;
row-area := TouchArea {
double-clicked => {
if (row.is-channel) {
Bridge.join-channel(row.id);
}
}
clicked => {
if (row.is-channel) {
Bridge.open-channel-chat(row.id);
}
}
}
HorizontalLayout {
padding-left: 8px + row.depth * 18px;
padding-right: 8px;
spacing: 6px;
if row.is-channel: Text {
text: row.collapsed ? "▸" : "▾";
vertical-alignment: center;
TouchArea {
clicked => { Bridge.toggle-collapse(row.id); }
}
}
if !row.is-channel: Rectangle {
width: 10px;
height: 10px;
y: (parent.height - self.height) / 2;
border-radius: 5px;
background: row.talking ? #3fb950 : #30363d;
}
Text {
text: (row.is-channel ? "# " : "") + row.name;
horizontal-stretch: 1;
horizontal-alignment: left;
vertical-alignment: center;
font-weight: row.is-channel || row.own ? 600 : 400;
color: row.away ? #8b949e : row.own ? #58a6ff : #e6edf3;
overflow: elide;
}
if row.locked: Text { text: "password"; font-size: 10px; color: #d29922; vertical-alignment: center; }
if row.muted: Text { text: "mic off"; font-size: 10px; color: #f85149; vertical-alignment: center; }
if row.sound-off: Text { text: "sound off"; font-size: 10px; color: #f85149; vertical-alignment: center; }
if row.streaming: Text { text: "LIVE"; font-size: 10px; color: #a371f7; vertical-alignment: center; }
if row.away: Text { text: "away"; font-size: 10px; color: #8b949e; vertical-alignment: center; }
}
}
}
}
component ChatPanel inherits Rectangle {
background: #0d1117;
VerticalLayout {
HorizontalLayout {
height: 34px;
spacing: 2px;
for tab[i] in Bridge.tabs: Rectangle {
width: tab-text.preferred-width + 28px;
background: Bridge.current-tab == i ? #30363d : tab-area.has-hover ? #21262d : #161b22;
tab-area := TouchArea {
clicked => { Bridge.select-tab(i); }
}
HorizontalLayout {
padding-left: 10px;
padding-right: 6px;
spacing: 4px;
tab-text := Text {
text: tab.title + (tab.unread > 0 ? " (" + tab.unread + ")" : "");
vertical-alignment: center;
font-weight: tab.unread > 0 ? 700 : 400;
}
if tab.kind == 1: Text {
text: "×";
vertical-alignment: center;
TouchArea {
clicked => { Bridge.close-tab(i); }
}
}
}
}
Rectangle { }
}
ListView {
for line in Bridge.messages: VerticalLayout {
padding: 6px;
HorizontalLayout {
spacing: 8px;
Text {
text: line.author;
font-weight: 700;
color: line.relayed ? #58a6ff : #e6edf3;
}
Text {
text: line.time + (line.relayed ? " via relay" : "");
font-size: 11px;
color: #8b949e;
vertical-alignment: center;
}
}
Text {
text: line.text;
wrap: word-wrap;
}
}
}
HorizontalLayout {
padding: 6px;
spacing: 6px;
input := LineEdit {
placeholder-text: "Message";
accepted(text) => {
if (text != "") {
Bridge.send-message(text);
self.text = "";
}
}
}
Button {
text: "Send";
clicked => {
if (input.text != "") {
Bridge.send-message(input.text);
input.text = "";
}
}
}
}
}
}
export component MainWindow inherits Window {
title: "TS Client";
preferred-width: 1200px;
preferred-height: 760px;
min-width: 360px;
min-height: 480px;
background: #0d1117;
default-font-size: 13px;
property <bool> editing: false;
property <bool> show-about: false;
property <BookmarkForm> form;
// Phones and narrow windows show one pane at a time. Set from a change
// handler: a binding on `width` would loop through the layout.
property <bool> narrow: false;
changed width => { narrow = self.width < 800px; }
init => { narrow = self.width < 800px; }
property <int> pane: 1;
VerticalLayout {
// Toolbar
Rectangle {
height: 48px;
background: #161b22;
HorizontalLayout {
padding: 6px;
spacing: 6px;
if narrow: Button {
text: pane == 0 ? "Tree" : pane == 1 ? "Chat" : "Servers";
clicked => { pane = mod(pane + 1, 3); }
}
Text {
text: Bridge.server-title;
font-size: 15px;
font-weight: 700;
vertical-alignment: center;
overflow: elide;
}
Rectangle { }
Button {
text: Bridge.voice-connected ? "Disconnect" : Bridge.voice-connecting ? "Connecting…" : "Connect";
enabled: Bridge.current-server >= 0 && !Bridge.voice-connecting;
primary: !Bridge.voice-connected;
clicked => {
if (Bridge.voice-connected) {
Bridge.disconnect-voice();
} else {
Bridge.connect-voice();
}
}
}
Button {
text: Bridge.observing ? "Stop observing" : "Observe (invisible)";
enabled: Bridge.can-observe;
clicked => { Bridge.toggle-observe(); }
}
Button {
text: Bridge.input-muted ? "Mic: off" : "Mic: on";
enabled: Bridge.voice-connected;
clicked => { Bridge.set-input-muted(!Bridge.input-muted); }
}
Button {
text: Bridge.output-muted ? "Sound: off" : "Sound: on";
enabled: Bridge.voice-connected;
clicked => { Bridge.set-output-muted(!Bridge.output-muted); }
}
ptt := Rectangle {
width: 110px;
border-radius: 4px;
background: Bridge.transmitting ? #238636 : ptt-area.has-hover ? #30363d : #21262d;
opacity: Bridge.voice-connected ? 1.0 : 0.4;
Text {
text: Bridge.transmitting ? "Talking…" : "Hold to talk";
}
ptt-area := TouchArea {
enabled: Bridge.voice-connected;
pointer-event(e) => {
if (e.kind == PointerEventKind.down) {
Bridge.push-to-talk(true);
} else if (e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel) {
Bridge.push-to-talk(false);
}
}
}
}
Button {
text: "About";
clicked => { show-about = true; }
}
}
}
HorizontalLayout {
if !narrow || pane == 2: ServerList {
// Fixed width beside the other panes, all the space alone.
min-width: narrow ? 0px : 230px;
max-width: narrow ? 100000px : 230px;
horizontal-stretch: narrow ? 1 : 0;
add => {
form = Bridge.edit-bookmark(-1);
editing = true;
}
edit(id) => {
form = Bridge.edit-bookmark(id);
editing = true;
}
}
if !narrow || pane == 0: ChannelTree {
min-width: narrow ? 0px : 360px;
max-width: narrow ? 100000px : 360px;
horizontal-stretch: narrow ? 1 : 0;
}
if !narrow || pane == 1: ChatPanel { }
}
// Status bar
Rectangle {
height: 26px;
background: #161b22;
HorizontalLayout {
padding-left: 8px;
padding-right: 8px;
Text {
text: Bridge.status-text;
color: #8b949e;
vertical-alignment: center;
overflow: elide;
}
Rectangle { }
Text {
text: Bridge.presence-source;
color: #58a6ff;
vertical-alignment: center;
}
}
}
}
if editing: BookmarkEditor {
form <=> form;
done => { editing = false; }
}
if show-about: Rectangle {
background: #000000c0;
TouchArea {
clicked => { show-about = false; }
}
VerticalBox {
alignment: center;
Text {
text: "Unofficial TeamSpeak 3/6 compatible client. Not affiliated with TeamSpeak Systems GmbH.";
horizontal-alignment: center;
wrap: word-wrap;
}
AboutSlint { }
Text {
text: "Third-party licenses: see THIRD_PARTY_NOTICES. Click to close.";
horizontal-alignment: center;
color: #8b949e;
}
}
}
}