M5 (part 2): Slint desktop UI (tsc-desktop)
- tsc-model: tree_rows/order_siblings (flattened channel tree in TeamSpeak's sibling order, collapsible). - tsc-ui: Slint (fluent-dark) window with server list and bookmark editor, channel tree (talking, muted, away, streaming, password markers; click opens channel chat, double-click joins), chat tabs with unread counts, connect/observe/mute/push-to-talk toolbar, narrow single-pane layout for small screens, About page with the Slint attribution. Engine events are marshalled to the UI thread; secrets go to the OS keyring (memory fallback). - Dev switches TSC_DATA_DIR, TSC_AUTOCONNECT and TSC_SCREENSHOT; the README screenshots were taken under Xvfb against the dev servers. - Workspace lint unsafe_code: deny (Slint's generated code needs a local allow). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
e4a9860727
commit
fe219dbf7b
13 files changed
+5148
-68
No files matched your search
@@ -21,7 +21,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install system dependencies
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev libfontconfig1-dev libxkbcommon-dev
|
||||
- name: Install toolchain (rust-toolchain.toml)
|
||||
run: rustup toolchain install
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install system dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev libfontconfig1-dev libxkbcommon-dev
|
||||
- name: Install toolchain (rust-toolchain.toml)
|
||||
run: rustup toolchain install
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install system dependencies
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
|
||||
run: sudo apt-get update && sudo apt-get install -y libasound2-dev libfontconfig1-dev libxkbcommon-dev
|
||||
- name: Install toolchain (rust-toolchain.toml)
|
||||
run: rustup toolchain install
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
Generated
+3656
-60
File diff suppressed because it is too large.
Load diff
+4
-1
@@ -16,6 +16,7 @@ members = [
|
||||
"crates/tsc-observer",
|
||||
"crates/tsc-query",
|
||||
"crates/tsc-store",
|
||||
"crates/tsc-ui",
|
||||
"tools/tsctl",
|
||||
]
|
||||
default-members = [
|
||||
@@ -33,6 +34,7 @@ default-members = [
|
||||
"crates/tsc-observer",
|
||||
"crates/tsc-query",
|
||||
"crates/tsc-store",
|
||||
"crates/tsc-ui",
|
||||
"tools/tsctl",
|
||||
]
|
||||
|
||||
@@ -44,7 +46,8 @@ repository = "https://github.com/Faumaray/teamspeak_client_rs"
|
||||
publish = false
|
||||
|
||||
[workspace.lints.rust]
|
||||
unsafe_code = "forbid"
|
||||
# deny, not forbid: generated code (Slint) needs a local allow.
|
||||
unsafe_code = "deny"
|
||||
|
||||
[workspace.lints.clippy]
|
||||
all = { level = "warn", priority = -1 }
|
||||
|
||||
@@ -23,7 +23,7 @@ See [docs/architecture.md](docs/architecture.md) for the design and milestones.
|
||||
|
||||
## Status
|
||||
|
||||
Done so far (milestones M0–M4 of [the plan](docs/architecture.md#milestones)):
|
||||
Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/architecture.md#milestones)):
|
||||
|
||||
- `crates/proto/`: vendored tsclientlib, modernised (TS6 fields and stream
|
||||
messages, faster off-thread Init1 puzzle, `curve25519-dalek` 4, fuzzing fixes;
|
||||
@@ -36,6 +36,9 @@ Done so far (milestones M0–M4 of [the plan](docs/architecture.md#milestones)):
|
||||
- `crates/tsc-gateway` (`tsgw`) + `tsc-gateway-proto`: companion gateway for server admins. Users log in
|
||||
with their TeamSpeak identity and get presence, channel chat and history without joining voice,
|
||||
limited by their server permissions ([admin guide](docs/gateway-admin.md))
|
||||
- `crates/tsc-core`: client engine; sessions merge voice, gateway and query sources, route chat, run audio
|
||||
- `crates/tsc-ui` (`tsc-desktop`): Slint desktop app: servers, channel tree with talking indicators,
|
||||
chat tabs (own channel via voice, other channels via relay), connect / observe invisibly, mute, push-to-talk
|
||||
- `tools/tsctl`: headless CLI: channel tree, chat, voice send/record, raw commands, stream events,
|
||||
`query`, `observe` (invisible presence), `relay` (channel chat without joining) and `gateway`
|
||||
- `dev/`: TeamSpeak 3.13 and TeamSpeak 6 (6.0.0-beta13.1) servers; `scripts/it-smoke.sh`
|
||||
@@ -43,11 +46,18 @@ Done so far (milestones M0–M4 of [the plan](docs/architecture.md#milestones)):
|
||||
relay chat and the gateway on both
|
||||
- `fuzz/`: cargo-fuzz targets for packets, commands and the license chain
|
||||
|
||||
No GUI and no screen sharing yet.
|
||||
No screen sharing yet, and no Android build yet.
|
||||
|
||||
| Connected with voice | Observing invisibly through the gateway |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
## Try it
|
||||
|
||||
```sh
|
||||
# Desktop app
|
||||
cargo run -p tsc-ui --bin tsc-desktop
|
||||
|
||||
# Local servers (use REGISTRY=mirror.gcr.io if Docker Hub rate-limits you)
|
||||
docker compose -f dev/docker-compose.yml up -d
|
||||
|
||||
@@ -71,8 +81,9 @@ scripts/it-smoke.sh # all of the above, on both servers
|
||||
Other commands: `tsctl identity new`, `tsctl versions`, `tsctl connect <addr> listen|chat|raw`.
|
||||
`tsctl --help` lists all options.
|
||||
|
||||
Building on Linux needs the ALSA headers (`libasound2-dev`) for the audio examples,
|
||||
plus CMake and a C compiler for the bundled libopus.
|
||||
Building on Linux needs the ALSA headers (`libasound2-dev`), fontconfig and xkbcommon
|
||||
headers for the UI (`libfontconfig1-dev libxkbcommon-dev`), plus CMake and a C compiler for
|
||||
the bundled libopus.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
mod chat;
|
||||
mod presence;
|
||||
mod server;
|
||||
mod tree;
|
||||
|
||||
pub use chat::{ChatMessage, ChatTarget, relay_text, split_message};
|
||||
pub use presence::{
|
||||
ChannelId, ChannelInfo, ClientId, ClientInfo, Presence, PresenceDelta, PresenceSnapshot,
|
||||
};
|
||||
pub use server::{Capabilities, ServerFlavor, ServerVersion};
|
||||
pub use tree::{TreeRow, order_siblings, tree_rows};
|
||||
@@ -0,0 +1,116 @@
|
||||
//! Flatten presence into display rows in TeamSpeak's channel order.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::presence::{ChannelId, ChannelInfo, ClientInfo, Presence};
|
||||
|
||||
/// One line of a channel tree.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TreeRow<'a> {
|
||||
Channel { depth: usize, channel: &'a ChannelInfo },
|
||||
Client { depth: usize, client: &'a ClientInfo },
|
||||
}
|
||||
|
||||
/// Sort siblings by following the `order` links (each channel names the
|
||||
/// sibling directly above it). Channels whose predecessor is missing are
|
||||
/// appended at the end, sorted by id, so nothing is ever dropped.
|
||||
pub fn order_siblings(mut siblings: Vec<&ChannelInfo>) -> Vec<&ChannelInfo> {
|
||||
siblings.sort_by_key(|c| c.id);
|
||||
let mut by_prev: HashMap<ChannelId, &ChannelInfo> = HashMap::new();
|
||||
for c in &siblings {
|
||||
by_prev.entry(c.order).or_insert(c);
|
||||
}
|
||||
let mut sorted = Vec::with_capacity(siblings.len());
|
||||
let mut prev = 0;
|
||||
while let Some(c) = by_prev.remove(&prev) {
|
||||
sorted.push(c);
|
||||
prev = c.id;
|
||||
}
|
||||
for c in siblings {
|
||||
if !sorted.iter().any(|s| s.id == c.id) {
|
||||
sorted.push(c);
|
||||
}
|
||||
}
|
||||
sorted
|
||||
}
|
||||
|
||||
/// Channels and their (non-query) clients, depth-first. Clients are sorted by
|
||||
/// name; `collapsed` channels hide their sub-channels and clients.
|
||||
pub fn tree_rows<'a>(p: &'a Presence, collapsed: &dyn Fn(ChannelId) -> bool) -> Vec<TreeRow<'a>> {
|
||||
let mut rows = Vec::new();
|
||||
add_level(p, 0, 0, collapsed, &mut rows);
|
||||
rows
|
||||
}
|
||||
|
||||
fn add_level<'a>(
|
||||
p: &'a Presence,
|
||||
parent: ChannelId,
|
||||
depth: usize,
|
||||
collapsed: &dyn Fn(ChannelId) -> bool,
|
||||
rows: &mut Vec<TreeRow<'a>>,
|
||||
) {
|
||||
let siblings = order_siblings(p.channels.values().filter(|c| c.parent == parent).collect());
|
||||
for channel in siblings {
|
||||
rows.push(TreeRow::Channel { depth, channel });
|
||||
if collapsed(channel.id) {
|
||||
continue;
|
||||
}
|
||||
let mut members: Vec<_> = p.members(channel.id).collect();
|
||||
members.sort_by(|a, b| a.nickname.to_lowercase().cmp(&b.nickname.to_lowercase()));
|
||||
for client in members {
|
||||
rows.push(TreeRow::Client { depth: depth + 1, client });
|
||||
}
|
||||
add_level(p, channel.id, depth + 1, collapsed, rows);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::presence::PresenceSnapshot;
|
||||
|
||||
fn ch(id: u64, parent: u64, order: u64, name: &str) -> ChannelInfo {
|
||||
ChannelInfo { id, parent, order, name: name.into(), ..Default::default() }
|
||||
}
|
||||
|
||||
fn cl(id: u16, name: &str, channel: u64) -> ClientInfo {
|
||||
ClientInfo { id, nickname: name.into(), channel, ..Default::default() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn follows_order_links() {
|
||||
let channels = [ch(5, 0, 3, "c"), ch(3, 0, 7, "b"), ch(7, 0, 0, "a")];
|
||||
let names: Vec<_> =
|
||||
order_siblings(channels.iter().collect()).iter().map(|c| c.name.as_str()).collect();
|
||||
assert_eq!(names, ["a", "b", "c"]);
|
||||
let broken = [ch(1, 0, 0, "a"), ch(2, 0, 99, "orphan")];
|
||||
assert_eq!(order_siblings(broken.iter().collect())[1].name, "orphan");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_depth_first_with_collapse() {
|
||||
let mut bot = cl(9, "bot", 1);
|
||||
bot.is_query = true;
|
||||
let p = Presence::from_snapshot(PresenceSnapshot {
|
||||
server_name: "s".into(),
|
||||
channels: vec![ch(1, 0, 0, "Lobby"), ch(2, 0, 1, "Games"), ch(3, 2, 0, "Squad")],
|
||||
clients: vec![cl(1, "zed", 1), cl(2, "Alice", 1), bot, cl(3, "Bob", 3)],
|
||||
});
|
||||
let describe = |rows: Vec<TreeRow>| -> Vec<String> {
|
||||
rows.iter()
|
||||
.map(|r| match r {
|
||||
TreeRow::Channel { depth, channel } => format!("{depth}#{}", channel.name),
|
||||
TreeRow::Client { depth, client } => format!("{depth}-{}", client.nickname),
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
assert_eq!(
|
||||
describe(tree_rows(&p, &|_| false)),
|
||||
["0#Lobby", "1-Alice", "1-zed", "0#Games", "1#Squad", "2-Bob"]
|
||||
);
|
||||
assert_eq!(
|
||||
describe(tree_rows(&p, &|c| c == 2)),
|
||||
["0#Lobby", "1-Alice", "1-zed", "0#Games"]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
[package]
|
||||
name = "tsc-ui"
|
||||
version = "0.1.0"
|
||||
description = "Slint user interface and the desktop binary."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "tsc-desktop"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.104"
|
||||
chrono = { version = "0.4.45", default-features = false, features = ["clock"] }
|
||||
dirs = "6"
|
||||
png = "0.18"
|
||||
slint = { version = "1.18", features = ["renderer-software"] }
|
||||
tokio = { version = "1.53.1", features = ["rt-multi-thread", "macros", "time", "sync"] }
|
||||
tracing = "0.1.44"
|
||||
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
|
||||
tsc-core = { path = "../tsc-core" }
|
||||
tsc-model = { path = "../tsc-model" }
|
||||
tsc-query = { path = "../tsc-query" }
|
||||
tsc-store = { path = "../tsc-store", features = ["keyring"] }
|
||||
tsclientlib = { path = "../proto/tsclientlib" }
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1.18"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
slint_build::compile_with_config(
|
||||
"ui/app.slint",
|
||||
slint_build::CompilerConfiguration::new().with_style("fluent-dark".into()),
|
||||
)
|
||||
.expect("slint compile");
|
||||
}
|
||||
@@ -0,0 +1,767 @@
|
||||
//! Application state on the UI thread, wired to the engine.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
||||
use tokio::runtime::Runtime;
|
||||
use tracing::warn;
|
||||
use tsc_core::{
|
||||
Command, Engine, Event, ObserveState, SessionState, Source, VoiceOptions, VoiceState,
|
||||
};
|
||||
use tsc_model::{ChannelId, ChatMessage, ChatTarget, Presence, TreeRow, tree_rows};
|
||||
use tsc_store::{Bookmark, MemorySecrets, QueryConfig, QueryTransport, Secrets, Store};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
/// Secrets in the OS keyring, or in memory when there is none (headless
|
||||
/// Linux without a Secret Service).
|
||||
struct FallbackSecrets {
|
||||
keyring: tsc_store::KeyringSecrets,
|
||||
memory: MemorySecrets,
|
||||
}
|
||||
|
||||
impl Secrets for FallbackSecrets {
|
||||
fn get(&self, key: &str) -> tsc_store::Result<Option<String>> {
|
||||
match self.memory.get(key)? {
|
||||
Some(v) => Ok(Some(v)),
|
||||
None => Ok(self.keyring.get(key).unwrap_or(None)),
|
||||
}
|
||||
}
|
||||
|
||||
fn set(&self, key: &str, value: &str) -> tsc_store::Result<()> {
|
||||
if let Err(error) = self.keyring.set(key, value) {
|
||||
warn!(%error, "keyring unavailable, keeping the secret for this session only");
|
||||
return self.memory.set(key, value);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn delete(&self, key: &str) -> tsc_store::Result<()> {
|
||||
let _ = self.keyring.delete(key);
|
||||
self.memory.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
struct Tab {
|
||||
target: ChatTarget,
|
||||
title: String,
|
||||
lines: Vec<ChatLine>,
|
||||
unread: i32,
|
||||
}
|
||||
|
||||
/// What we know about one server session.
|
||||
struct SessionView {
|
||||
state: SessionState,
|
||||
presence: Arc<Presence>,
|
||||
collapsed: HashSet<ChannelId>,
|
||||
talking: HashSet<u16>,
|
||||
tabs: Vec<Tab>,
|
||||
current_tab: usize,
|
||||
/// The own channel's tab was focused for this voice connection.
|
||||
focused_own_channel: bool,
|
||||
}
|
||||
|
||||
impl Default for SessionView {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
state: SessionState::default(),
|
||||
presence: Arc::default(),
|
||||
collapsed: HashSet::new(),
|
||||
talking: HashSet::new(),
|
||||
tabs: vec![Tab {
|
||||
target: ChatTarget::Server,
|
||||
title: "Server".into(),
|
||||
lines: Vec::new(),
|
||||
unread: 0,
|
||||
}],
|
||||
current_tab: 0,
|
||||
focused_own_channel: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct App {
|
||||
ui: slint::Weak<MainWindow>,
|
||||
store: Store,
|
||||
secrets: Box<dyn Secrets>,
|
||||
engine: Engine,
|
||||
identity: tsclientlib::Identity,
|
||||
bookmarks: Vec<Bookmark>,
|
||||
current: Option<i64>,
|
||||
sessions: HashMap<i64, SessionView>,
|
||||
status: String,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static APP: RefCell<Option<App>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
fn with_app<R>(f: impl FnOnce(&mut App) -> R) -> Option<R> {
|
||||
APP.with(|app| app.borrow_mut().as_mut().map(f))
|
||||
}
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
let runtime = Runtime::new()?;
|
||||
let engine = runtime.block_on(async { Engine::start() });
|
||||
|
||||
// Development switches: TSC_DATA_DIR isolates the database,
|
||||
// TSC_AUTOCONNECT=voice|observe connects the first bookmark on start,
|
||||
// TSC_SCREENSHOT=<png> saves the window after TSC_SCREENSHOT_DELAY seconds and exits.
|
||||
let dir = match std::env::var_os("TSC_DATA_DIR") {
|
||||
Some(dir) => dir.into(),
|
||||
None => dirs::data_dir().unwrap_or_else(|| ".".into()).join("tsc"),
|
||||
};
|
||||
let store =
|
||||
Store::open(&dir.join("client.db")).context("failed to open the client database")?;
|
||||
let identity = match store.identities()?.first() {
|
||||
Some(entry) => store.identity(entry.id)?,
|
||||
None => {
|
||||
// Creating an identity takes a moment (security level 8).
|
||||
let identity = tsclientlib::Identity::create();
|
||||
store.add_identity("Default", &identity)?;
|
||||
identity
|
||||
}
|
||||
};
|
||||
|
||||
let ui = MainWindow::new()?;
|
||||
let bookmarks = store.bookmarks()?;
|
||||
let app = App {
|
||||
ui: ui.as_weak(),
|
||||
store,
|
||||
secrets: Box::new(FallbackSecrets {
|
||||
keyring: tsc_store::KeyringSecrets::new("tsc-client"),
|
||||
memory: MemorySecrets::default(),
|
||||
}),
|
||||
engine: engine.clone(),
|
||||
identity,
|
||||
current: bookmarks.first().map(|b| b.id),
|
||||
bookmarks,
|
||||
sessions: HashMap::new(),
|
||||
status: "Ready".into(),
|
||||
};
|
||||
APP.with(|a| *a.borrow_mut() = Some(app));
|
||||
wire_callbacks(&ui);
|
||||
with_app(|app| app.refresh_all());
|
||||
|
||||
// Engine events -> UI thread.
|
||||
let mut events = engine.subscribe();
|
||||
runtime.spawn(async move {
|
||||
loop {
|
||||
match events.recv().await {
|
||||
Ok(event) => {
|
||||
let _ = slint::invoke_from_event_loop(move || {
|
||||
with_app(|app| app.handle_event(event));
|
||||
});
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
match std::env::var("TSC_AUTOCONNECT").as_deref() {
|
||||
Ok("voice") => {
|
||||
with_app(|app| app.connect_voice());
|
||||
}
|
||||
Ok("observe") => {
|
||||
with_app(|app| app.toggle_observe());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let _screenshot_timer = std::env::var_os("TSC_SCREENSHOT").map(|path| {
|
||||
let delay =
|
||||
std::env::var("TSC_SCREENSHOT_DELAY").ok().and_then(|d| d.parse().ok()).unwrap_or(4);
|
||||
let weak = ui.as_weak();
|
||||
let timer = slint::Timer::default();
|
||||
timer.start(
|
||||
slint::TimerMode::SingleShot,
|
||||
std::time::Duration::from_secs(delay),
|
||||
move || {
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
if let Err(e) = save_screenshot(&ui, std::path::Path::new(&path)) {
|
||||
eprintln!("screenshot failed: {e}");
|
||||
}
|
||||
let _ = ui.hide();
|
||||
}
|
||||
},
|
||||
);
|
||||
timer
|
||||
});
|
||||
|
||||
ui.run()?;
|
||||
APP.with(|a| a.borrow_mut().take());
|
||||
runtime.shutdown_timeout(std::time::Duration::from_secs(2));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn wire_callbacks(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.on_select_server(|id| {
|
||||
with_app(|app| {
|
||||
app.current = Some(id as i64);
|
||||
app.refresh_all();
|
||||
});
|
||||
});
|
||||
bridge.on_connect_voice(|| {
|
||||
with_app(|app| app.connect_voice());
|
||||
});
|
||||
bridge.on_disconnect_voice(|| {
|
||||
with_app(|app| app.command(|session| Command::DisconnectVoice { session }));
|
||||
});
|
||||
bridge.on_toggle_observe(|| {
|
||||
with_app(|app| app.toggle_observe());
|
||||
});
|
||||
bridge.on_join_channel(|cid| {
|
||||
with_app(|app| {
|
||||
app.command(|session| Command::MoveToChannel {
|
||||
session,
|
||||
channel: cid as ChannelId,
|
||||
password: None,
|
||||
})
|
||||
});
|
||||
});
|
||||
bridge.on_open_channel_chat(|cid| {
|
||||
with_app(|app| app.open_chat(ChatTarget::Channel(cid as ChannelId), true));
|
||||
});
|
||||
bridge.on_toggle_collapse(|cid| {
|
||||
with_app(|app| {
|
||||
if let Some(view) = app.view_mut() {
|
||||
let cid = cid as ChannelId;
|
||||
if !view.collapsed.remove(&cid) {
|
||||
view.collapsed.insert(cid);
|
||||
}
|
||||
}
|
||||
app.refresh_tree();
|
||||
});
|
||||
});
|
||||
bridge.on_select_tab(|i| {
|
||||
with_app(|app| {
|
||||
if let Some(view) = app.view_mut() {
|
||||
view.current_tab = i as usize;
|
||||
if let Some(tab) = view.tabs.get_mut(i as usize) {
|
||||
tab.unread = 0;
|
||||
}
|
||||
}
|
||||
app.refresh_chat();
|
||||
});
|
||||
});
|
||||
bridge.on_close_tab(|i| {
|
||||
with_app(|app| app.close_tab(i as usize));
|
||||
});
|
||||
bridge.on_send_message(|text| {
|
||||
with_app(|app| app.send_message(text.to_string()));
|
||||
});
|
||||
bridge.on_set_input_muted(|muted| {
|
||||
with_app(|app| app.command(|session| Command::SetInputMuted { session, muted }));
|
||||
});
|
||||
bridge.on_set_output_muted(|muted| {
|
||||
with_app(|app| app.command(|session| Command::SetOutputMuted { session, muted }));
|
||||
});
|
||||
bridge.on_push_to_talk(|on| {
|
||||
with_app(|app| app.command(|session| Command::SetTransmitting { session, on }));
|
||||
});
|
||||
bridge.on_edit_bookmark(|id| with_app(|app| app.bookmark_form(id as i64)).unwrap_or_default());
|
||||
bridge.on_save_bookmark(|form| {
|
||||
with_app(|app| app.save_bookmark(form));
|
||||
});
|
||||
bridge.on_delete_bookmark(|id| {
|
||||
with_app(|app| app.delete_bookmark(id as i64));
|
||||
});
|
||||
}
|
||||
|
||||
fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> {
|
||||
let image = ui.window().take_snapshot()?;
|
||||
let file = std::io::BufWriter::new(std::fs::File::create(path)?);
|
||||
let mut encoder = png::Encoder::new(file, image.width(), image.height());
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
encoder.set_depth(png::BitDepth::Eight);
|
||||
encoder.write_header()?.write_image_data(image.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn time_of(ts_ms: i64) -> String {
|
||||
chrono::DateTime::from_timestamp_millis(ts_ms)
|
||||
.map(|t| t.with_timezone(&chrono::Local).format("%H:%M").to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn model<T: Clone + 'static>(items: Vec<T>) -> ModelRc<T> {
|
||||
ModelRc::from(Rc::new(VecModel::from(items)))
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn view_mut(&mut self) -> Option<&mut SessionView> {
|
||||
let id = self.current?;
|
||||
Some(self.sessions.entry(id).or_default())
|
||||
}
|
||||
|
||||
fn bookmark(&self, id: i64) -> Option<&Bookmark> {
|
||||
self.bookmarks.iter().find(|b| b.id == id)
|
||||
}
|
||||
|
||||
fn command(&self, f: impl FnOnce(u64) -> Command) {
|
||||
if let Some(id) = self.current {
|
||||
self.engine.send(f(id as u64));
|
||||
}
|
||||
}
|
||||
|
||||
fn set_status(&mut self, text: impl Into<String>) {
|
||||
self.status = text.into();
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
ui.global::<Bridge>().set_status_text(self.status.clone().into());
|
||||
}
|
||||
}
|
||||
|
||||
fn connect_voice(&mut self) {
|
||||
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return };
|
||||
let mut options = VoiceOptions::new(&b.address, &b.nickname);
|
||||
options.identity = Some(self.identity.clone());
|
||||
options.server_password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
||||
options.channel = b.default_channel.clone();
|
||||
options.audio = true;
|
||||
self.engine
|
||||
.send(Command::ConnectVoice { session: b.id as u64, options: Box::new(options) });
|
||||
self.set_status(format!("Connecting to {}…", b.address));
|
||||
}
|
||||
|
||||
fn toggle_observe(&mut self) {
|
||||
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return };
|
||||
let session = b.id as u64;
|
||||
let observing =
|
||||
self.sessions.get(&b.id).is_some_and(|v| v.state.observe != ObserveState::Off);
|
||||
if observing {
|
||||
self.engine.send(Command::StopObserving { session });
|
||||
return;
|
||||
}
|
||||
if let Some(url) = &b.gateway_url {
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
url: url.clone(),
|
||||
identity: Box::new(self.identity.clone()),
|
||||
});
|
||||
} else if let Some(q) = &b.query {
|
||||
let secret = self.secrets.get(&b.query_password_key()).ok().flatten();
|
||||
let transport = match q.transport {
|
||||
QueryTransport::Raw => tsc_query::Transport::Raw,
|
||||
QueryTransport::Ssh => tsc_query::Transport::Ssh,
|
||||
QueryTransport::Http => tsc_query::Transport::Http,
|
||||
};
|
||||
let connect = tsc_query::Connect {
|
||||
transport,
|
||||
addr: format!("{}:{}", q.host, q.port),
|
||||
user: q.user.clone(),
|
||||
secret,
|
||||
server_port: q.server_port,
|
||||
server_id: None,
|
||||
line: Default::default(),
|
||||
};
|
||||
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
|
||||
}
|
||||
self.set_status("Observing invisibly…");
|
||||
}
|
||||
|
||||
fn open_chat(&mut self, target: ChatTarget, focus: bool) {
|
||||
let Some(id) = self.current else { return };
|
||||
let title = match &target {
|
||||
ChatTarget::Channel(cid) => {
|
||||
let name = self
|
||||
.sessions
|
||||
.get(&id)
|
||||
.and_then(|v| v.presence.channels.get(cid).map(|c| c.name.clone()));
|
||||
format!("#{}", name.unwrap_or_else(|| cid.to_string()))
|
||||
}
|
||||
ChatTarget::Server => "Server".into(),
|
||||
ChatTarget::Private(uid) => format!("@{uid}"),
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let index = match view.tabs.iter().position(|t| t.target == target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
view.tabs.push(Tab { target: target.clone(), title, lines: Vec::new(), unread: 0 });
|
||||
self.engine.send(Command::OpenChat { session: id as u64, target });
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
};
|
||||
if focus {
|
||||
view.current_tab = index;
|
||||
view.tabs[index].unread = 0;
|
||||
}
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
fn close_tab(&mut self, index: usize) {
|
||||
let Some(id) = self.current else { return };
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
if index == 0 || index >= view.tabs.len() {
|
||||
return;
|
||||
}
|
||||
let tab = view.tabs.remove(index);
|
||||
view.current_tab = view.current_tab.min(view.tabs.len() - 1);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
fn send_message(&mut self, text: String) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let target = view.tabs[view.current_tab].target.clone();
|
||||
self.engine.send(Command::SendChat { session: id as u64, target, text });
|
||||
}
|
||||
|
||||
fn bookmark_form(&self, id: i64) -> BookmarkForm {
|
||||
let Some(b) = self.bookmark(id) else {
|
||||
return BookmarkForm {
|
||||
id: -1,
|
||||
nickname: std::env::var("USER").unwrap_or_default().into(),
|
||||
query_transport: "none".into(),
|
||||
query_user: "serveradmin".into(),
|
||||
..Default::default()
|
||||
};
|
||||
};
|
||||
let secret = |key: String| -> SharedString {
|
||||
self.secrets.get(&key).ok().flatten().unwrap_or_default().into()
|
||||
};
|
||||
let (transport, addr, user) = match &b.query {
|
||||
Some(q) => (
|
||||
match q.transport {
|
||||
QueryTransport::Raw => "raw",
|
||||
QueryTransport::Ssh => "ssh",
|
||||
QueryTransport::Http => "http",
|
||||
},
|
||||
format!("{}:{}", q.host, q.port),
|
||||
q.user.clone(),
|
||||
),
|
||||
None => ("none", String::new(), "serveradmin".to_string()),
|
||||
};
|
||||
BookmarkForm {
|
||||
id: b.id as i32,
|
||||
name: b.name.clone().into(),
|
||||
address: b.address.clone().into(),
|
||||
nickname: b.nickname.clone().into(),
|
||||
server_password: secret(b.server_password_key()),
|
||||
gateway_url: b.gateway_url.clone().unwrap_or_default().into(),
|
||||
query_transport: transport.into(),
|
||||
query_addr: addr.into(),
|
||||
query_user: user.into(),
|
||||
query_password: secret(b.query_password_key()),
|
||||
}
|
||||
}
|
||||
|
||||
fn save_bookmark(&mut self, form: BookmarkForm) {
|
||||
let query = match form.query_transport.as_str() {
|
||||
"none" | "" => None,
|
||||
t => {
|
||||
let (host, port) = form
|
||||
.query_addr
|
||||
.rsplit_once(':')
|
||||
.map_or((form.query_addr.to_string(), None), |(h, p)| {
|
||||
(h.to_string(), p.parse().ok())
|
||||
});
|
||||
let transport = match t {
|
||||
"raw" => QueryTransport::Raw,
|
||||
"http" => QueryTransport::Http,
|
||||
_ => QueryTransport::Ssh,
|
||||
};
|
||||
let default_port = match transport {
|
||||
QueryTransport::Raw => 10011,
|
||||
QueryTransport::Ssh => 10022,
|
||||
QueryTransport::Http => 10080,
|
||||
};
|
||||
Some(QueryConfig {
|
||||
transport,
|
||||
host,
|
||||
port: port.unwrap_or(default_port),
|
||||
user: form.query_user.to_string(),
|
||||
server_port: None,
|
||||
})
|
||||
}
|
||||
};
|
||||
let mut bookmark = Bookmark {
|
||||
id: form.id as i64,
|
||||
name: if form.name.is_empty() {
|
||||
form.address.to_string()
|
||||
} else {
|
||||
form.name.to_string()
|
||||
},
|
||||
address: form.address.to_string(),
|
||||
nickname: form.nickname.to_string(),
|
||||
identity: None,
|
||||
default_channel: None,
|
||||
gateway_url: Some(form.gateway_url.to_string()).filter(|u| !u.is_empty()),
|
||||
query,
|
||||
client_version: None,
|
||||
};
|
||||
let result = if bookmark.id < 0 {
|
||||
self.store.add_bookmark(&bookmark).map(|id| bookmark.id = id)
|
||||
} else {
|
||||
self.store.update_bookmark(&bookmark)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
self.set_status(format!("Could not save: {e}"));
|
||||
return;
|
||||
}
|
||||
for (key, value) in [
|
||||
(bookmark.server_password_key(), &form.server_password),
|
||||
(bookmark.query_password_key(), &form.query_password),
|
||||
] {
|
||||
let result = if value.is_empty() {
|
||||
self.secrets.delete(&key)
|
||||
} else {
|
||||
self.secrets.set(&key, value)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
warn!(%e, "could not store secret");
|
||||
}
|
||||
}
|
||||
self.current = Some(bookmark.id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
fn delete_bookmark(&mut self, id: i64) {
|
||||
self.engine.send(Command::CloseSession { session: id as u64 });
|
||||
if let Some(b) = self.bookmark(id).cloned() {
|
||||
let _ = self.secrets.delete(&b.server_password_key());
|
||||
let _ = self.secrets.delete(&b.query_password_key());
|
||||
}
|
||||
let _ = self.store.delete_bookmark(id);
|
||||
self.sessions.remove(&id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.current = self.bookmarks.first().map(|b| b.id);
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, event: Event) {
|
||||
match event {
|
||||
Event::State { session, state } => {
|
||||
let id = session as i64;
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let was_voice = view.state.voice;
|
||||
view.state = state.clone();
|
||||
if state.voice != VoiceState::Connected {
|
||||
view.focused_own_channel = false;
|
||||
}
|
||||
let focus = !view.focused_own_channel;
|
||||
if state.voice == VoiceState::Connected && was_voice != VoiceState::Connected {
|
||||
self.set_status("Connected");
|
||||
}
|
||||
if self.current == Some(id) {
|
||||
// The voice channel's chat is always at hand, and focused
|
||||
// once per connection.
|
||||
if let (Some(cid), VoiceState::Connected) = (state.own_channel, state.voice) {
|
||||
self.open_chat(ChatTarget::Channel(cid), focus);
|
||||
self.sessions.entry(id).or_default().focused_own_channel = true;
|
||||
}
|
||||
}
|
||||
self.refresh_servers();
|
||||
self.refresh_toolbar();
|
||||
}
|
||||
Event::ServerInfo { session, name, flavor, .. } => {
|
||||
if self.current == Some(session as i64) {
|
||||
let kind = match flavor {
|
||||
tsc_model::ServerFlavor::Ts3(v) => format!("TeamSpeak 3 {v}"),
|
||||
tsc_model::ServerFlavor::Ts6(v) => format!("TeamSpeak 6 {v}"),
|
||||
tsc_model::ServerFlavor::Unknown(v) => v,
|
||||
};
|
||||
self.set_status(format!("Connected to {name} ({kind})"));
|
||||
}
|
||||
}
|
||||
Event::Presence { session, presence } => {
|
||||
self.sessions.entry(session as i64).or_default().presence = presence;
|
||||
if self.current == Some(session as i64) {
|
||||
self.refresh_tree();
|
||||
self.refresh_chat();
|
||||
}
|
||||
}
|
||||
Event::Talking { session, client, talking } => {
|
||||
let view = self.sessions.entry(session as i64).or_default();
|
||||
if talking {
|
||||
view.talking.insert(client);
|
||||
} else {
|
||||
view.talking.remove(&client);
|
||||
}
|
||||
if self.current == Some(session as i64) {
|
||||
self.refresh_tree();
|
||||
}
|
||||
}
|
||||
Event::Chat { session, message } => self.add_message(session as i64, message),
|
||||
Event::Error { message, .. } => self.set_status(message),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_message(&mut self, id: i64, message: ChatMessage) {
|
||||
let current = self.current == Some(id);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let index = match view.tabs.iter().position(|t| t.target == message.target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
let title = match &message.target {
|
||||
ChatTarget::Channel(cid) => format!(
|
||||
"#{}",
|
||||
view.presence
|
||||
.channels
|
||||
.get(cid)
|
||||
.map(|c| c.name.clone())
|
||||
.unwrap_or_else(|| cid.to_string())
|
||||
),
|
||||
ChatTarget::Private(_) => format!("@{}", message.author_name),
|
||||
ChatTarget::Server => "Server".into(),
|
||||
};
|
||||
view.tabs.push(Tab {
|
||||
target: message.target.clone(),
|
||||
title,
|
||||
lines: Vec::new(),
|
||||
unread: 0,
|
||||
});
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
};
|
||||
let tab = &mut view.tabs[index];
|
||||
tab.lines.push(ChatLine {
|
||||
author: message.author_name.into(),
|
||||
text: message.text.into(),
|
||||
time: time_of(message.ts_ms).into(),
|
||||
relayed: message.via_relay,
|
||||
});
|
||||
if !(current && view.current_tab == index) {
|
||||
tab.unread += 1;
|
||||
}
|
||||
if current {
|
||||
self.refresh_chat();
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_all(&mut self) {
|
||||
self.refresh_servers();
|
||||
self.refresh_toolbar();
|
||||
self.refresh_tree();
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
fn refresh_servers(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let items = self
|
||||
.bookmarks
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let state = self.sessions.get(&b.id).map(|v| v.state.clone()).unwrap_or_default();
|
||||
let status = match (state.voice, state.observe) {
|
||||
(VoiceState::Connected, _) => "connected",
|
||||
(VoiceState::Connecting, _) | (_, ObserveState::Connecting) => "connecting",
|
||||
(_, ObserveState::Observing) => "observing",
|
||||
_ => "offline",
|
||||
};
|
||||
ServerItem {
|
||||
id: b.id as i32,
|
||||
name: b.name.clone().into(),
|
||||
address: b.address.clone().into(),
|
||||
status: status.into(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
bridge.set_servers(model(items));
|
||||
bridge.set_current_server(self.current.map_or(-1, |id| id as i32));
|
||||
}
|
||||
|
||||
fn refresh_toolbar(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let bookmark = self.current.and_then(|id| self.bookmark(id));
|
||||
let state = self
|
||||
.current
|
||||
.and_then(|id| self.sessions.get(&id))
|
||||
.map(|v| v.state.clone())
|
||||
.unwrap_or_default();
|
||||
bridge.set_server_title(
|
||||
bookmark.map_or("No server selected".into(), |b| b.name.clone()).into(),
|
||||
);
|
||||
bridge.set_voice_connected(state.voice == VoiceState::Connected);
|
||||
bridge.set_voice_connecting(state.voice == VoiceState::Connecting);
|
||||
bridge.set_observing(state.observe != ObserveState::Off);
|
||||
bridge.set_can_observe(
|
||||
bookmark.is_some_and(|b| b.gateway_url.is_some() || b.query.is_some()),
|
||||
);
|
||||
bridge.set_input_muted(state.input_muted);
|
||||
bridge.set_output_muted(state.output_muted);
|
||||
bridge.set_transmitting(state.transmitting);
|
||||
bridge.set_presence_source(
|
||||
match state.presence_source {
|
||||
Some(Source::Voice) => "live (voice)",
|
||||
Some(Source::Gateway) => "invisible (gateway)",
|
||||
Some(Source::Query) => "invisible (query)",
|
||||
None => "",
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
bridge.set_status_text(self.status.clone().into());
|
||||
}
|
||||
|
||||
fn refresh_tree(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let Some(view) = self.current.and_then(|id| self.sessions.get(&id)) else {
|
||||
ui.global::<Bridge>().set_tree(model(Vec::new()));
|
||||
return;
|
||||
};
|
||||
let own_channel = view.state.own_channel;
|
||||
let rows = tree_rows(&view.presence, &|cid| view.collapsed.contains(&cid))
|
||||
.into_iter()
|
||||
.map(|row| match row {
|
||||
TreeRow::Channel { depth, channel } => TreeItem {
|
||||
is_channel: true,
|
||||
depth: depth as i32,
|
||||
id: channel.id as i32,
|
||||
name: channel.name.clone().into(),
|
||||
own: own_channel == Some(channel.id),
|
||||
locked: channel.has_password,
|
||||
collapsed: view.collapsed.contains(&channel.id),
|
||||
..Default::default()
|
||||
},
|
||||
TreeRow::Client { depth, client } => TreeItem {
|
||||
is_channel: false,
|
||||
depth: depth as i32,
|
||||
id: client.id as i32,
|
||||
name: client.nickname.clone().into(),
|
||||
own: false,
|
||||
talking: view.talking.contains(&client.id) || client.talking == Some(true),
|
||||
muted: client.input_muted,
|
||||
sound_off: client.output_muted,
|
||||
away: client.away.is_some(),
|
||||
streaming: client.streaming == Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
ui.global::<Bridge>().set_tree(model(rows));
|
||||
}
|
||||
|
||||
fn refresh_chat(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let Some(view) = self.current.and_then(|id| self.sessions.get(&id)) else {
|
||||
bridge.set_tabs(model(vec![ChatTab { title: "Server".into(), ..Default::default() }]));
|
||||
bridge.set_messages(model(Vec::new()));
|
||||
return;
|
||||
};
|
||||
let tabs = view
|
||||
.tabs
|
||||
.iter()
|
||||
.map(|t| ChatTab {
|
||||
title: t.title.clone().into(),
|
||||
kind: matches!(t.target, ChatTarget::Channel(_)) as i32,
|
||||
id: match t.target {
|
||||
ChatTarget::Channel(cid) => cid as i32,
|
||||
_ => 0,
|
||||
},
|
||||
unread: t.unread,
|
||||
})
|
||||
.collect();
|
||||
bridge.set_tabs(model(tabs));
|
||||
bridge.set_current_tab(view.current_tab as i32);
|
||||
bridge.set_messages(model(view.tabs[view.current_tab].lines.clone()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//! Desktop client.
|
||||
|
||||
mod app;
|
||||
|
||||
use anyhow::Result;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn")),
|
||||
)
|
||||
.init();
|
||||
app::run()
|
||||
}
|
||||
@@ -0,0 +1,529 @@
|
||||
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.
|
||||
property <bool> 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 {
|
||||
width: narrow ? parent.width : 230px;
|
||||
add => {
|
||||
form = Bridge.edit-bookmark(-1);
|
||||
editing = true;
|
||||
}
|
||||
edit(id) => {
|
||||
form = Bridge.edit-bookmark(id);
|
||||
editing = true;
|
||||
}
|
||||
}
|
||||
if !narrow || pane == 0: ChannelTree {
|
||||
width: narrow ? parent.width : 360px;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Reference in new issue
Block a user