ui: servers observe on selection; no gateway or query fields

Selecting a server (or saving one) observes it invisibly through its
gateway, else a query login an older version stored; without a gateway it
is looked up from the address (SRV, then /.well-known/tsgw) and observing
starts once found. The Observe button and the menu entry are gone.

The add/edit server dialog no longer asks for a gateway URL or ServerQuery
login: Advanced keeps the name and nickname. A new address drops the
gateway and query login of the old server, so they are looked up again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VZBWxxMsxUzp4PSTKVzbZN
This commit is contained in:
Claude committed 2026-10-04 21:10:59 +00:00
1 parent d4a178b079
commit 7582fc12b5
10 files changed
+103 -179

No files matched your search

-3
View File
@@ -23,9 +23,6 @@ pub(super) fn wire(ui: &MainWindow) {
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 {
+5 -1
View File
@@ -160,7 +160,11 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
with_app(|app| app.connect_voice());
}
Some("observe") => {
with_app(|app| app.toggle_observe());
with_app(|app| {
if let Some(id) = app.current {
app.observe(id);
}
});
}
_ => {}
}
+59 -94
View File
@@ -5,7 +5,7 @@ use slint::{ComponentHandle, SharedString};
use tracing::warn;
use voelin_core::identity::LaunchImport;
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
use voelin_store::{Bookmark, QueryConfig, QueryTransport};
use voelin_store::{Bookmark, QueryTransport};
use crate::app::{App, BookmarkForm, Bridge, SessionView, later};
use crate::vm;
@@ -35,7 +35,9 @@ pub(crate) fn imported_status(report: &LaunchImport) -> Option<String> {
/// like the identity, the default channel or the client version, stays; a
/// new server has none of it). Only the address is needed: the name is the
/// address until the server tells its own (`adopt_server_name`), the
/// nickname `default_nickname`, the gateway is looked up later.
/// nickname `default_nickname`, the gateway is looked up in DNS
/// (`discover_gateway`). A new address drops the gateway and the query
/// login found or set for the old one.
fn bookmark_from_form(
old: Option<&Bookmark>,
form: &BookmarkForm,
@@ -46,6 +48,8 @@ fn bookmark_from_form(
bookmark.address = form.address.trim().to_string();
if old.is_some_and(|old| old.address != bookmark.address) {
bookmark.cached_server_icon = None;
bookmark.gateway_url = None;
bookmark.query = None;
}
bookmark.name = match form.name.trim() {
"" => bookmark.address.clone(),
@@ -55,35 +59,6 @@ fn bookmark_from_form(
"" => default_nickname(),
nickname => nickname.to_string(),
};
bookmark.gateway_url = Some(form.gateway_url.trim().to_string()).filter(|u| !u.is_empty());
bookmark.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: bookmark.query.as_ref().and_then(|q| q.server_port),
})
}
};
bookmark
}
@@ -174,7 +149,8 @@ impl App {
}
/// A gateway was found for the server at `address`; it is kept unless
/// the server changed meanwhile.
/// the server changed meanwhile, and the server is observed through it
/// if it is the one shown.
fn gateway_found(&mut self, id: i64, address: &str, url: String) {
let Some(b) = self
.bookmarks
@@ -191,6 +167,9 @@ impl App {
}
self.set_status(format!("Found the gateway of {name}: {url}"));
self.refresh_toolbar();
if self.current == Some(id) {
self.observe(id);
}
}
/// The server told its name: a server still named by its address takes
@@ -210,13 +189,19 @@ impl App {
self.refresh_toolbar();
}
pub(crate) fn toggle_observe(&mut self) {
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return };
/// Observe the server invisibly, unless it is already: through its
/// gateway, else its own query login. Without either the gateway is
/// looked up first, and observing starts when it is found
/// (`gateway_found`).
pub(crate) fn observe(&mut self, id: i64) {
let Some(b) = self.bookmark(id).cloned() else { return };
if self.demo_ui {
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 {
@@ -242,13 +227,18 @@ impl App {
line: Default::default(),
};
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
} else {
self.discover_gateway(b.id);
return;
}
self.set_status("Observing invisibly…");
}
/// Show a server, and observe it.
pub(crate) fn select_server(&mut self, id: i64) {
self.current = Some(id);
self.refresh_all();
self.observe(id);
}
pub(crate) fn bookmark_form(&self, id: i64) -> BookmarkForm {
@@ -256,26 +246,12 @@ impl App {
return BookmarkForm {
id: -1,
nickname: self.default_nickname().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,
// Named by its address: empty, so a new address names it again.
@@ -283,17 +259,12 @@ impl App {
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()),
}
}
pub(crate) fn save_bookmark(&mut self, form: BookmarkForm) {
let mut bookmark =
bookmark_from_form(self.bookmark(form.id as i64), &form, || self.default_nickname());
let old = self.bookmark(form.id as i64).cloned();
let mut bookmark = bookmark_from_form(old.as_ref(), &form, || self.default_nickname());
let result = if bookmark.id < 0 {
self.store.add_bookmark(&bookmark).map(|id| bookmark.id = id)
} else {
@@ -303,23 +274,27 @@ impl App {
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");
let key = bookmark.server_password_key();
let result = if form.server_password.is_empty() {
self.secrets.delete(&key)
} else {
self.secrets.set(&key, &form.server_password)
};
if let Err(e) = result {
warn!(%e, "could not store secret");
}
// Another server: what was observed is the old one's.
if let Some(old) = old.filter(|old| old.address != bookmark.address) {
if old.query.is_some() {
let _ = self.secrets.delete(&old.query_password_key());
}
self.engine.send(Command::StopObserving { session: bookmark.id as u64 });
if let Some(view) = self.sessions.get_mut(&bookmark.id) {
view.state.observe = ObserveState::Off;
}
}
self.current = Some(bookmark.id);
self.bookmarks = self.store.bookmarks().unwrap_or_default();
self.refresh_all();
self.discover_gateway(bookmark.id);
self.select_server(bookmark.id);
}
pub(crate) fn delete_bookmark(&mut self, id: i64) {
@@ -436,9 +411,6 @@ impl App {
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);
@@ -558,6 +530,7 @@ mod tests {
use voelin_core::identity::Found;
use super::*;
use voelin_store::QueryConfig;
#[test]
fn edited_server_rejects_queued_icons_and_failed_reconnect_keeps_them_hidden() {
@@ -600,12 +573,8 @@ mod tests {
#[test]
fn the_address_alone_makes_a_server() {
let form = BookmarkForm {
id: -1,
address: " ts.example.test ".into(),
query_transport: "none".into(),
..Default::default()
};
let form =
BookmarkForm { id: -1, address: " ts.example.test ".into(), ..Default::default() };
let b = bookmark_from_form(None, &form, || "Nick".into());
assert_eq!((b.address.as_str(), b.name.as_str()), ("ts.example.test", "ts.example.test"));
assert_eq!(b.nickname, "Nick");
@@ -632,31 +601,27 @@ mod tests {
id: 1234,
}),
};
let form = BookmarkForm {
// Same address: the gateway found and the query login stay.
let same = BookmarkForm {
id: 7,
name: "Mine".into(),
address: "new.example.test:9988".into(),
address: "old.example.test".into(),
nickname: "Other".into(),
// Cleared: looked up again.
gateway_url: "".into(),
query_transport: "raw".into(),
query_addr: "q.example.test".into(),
query_user: "serveradmin".into(),
..Default::default()
};
let b = bookmark_from_form(Some(&old), &form, || unreachable!("a nickname was given"));
let b = bookmark_from_form(Some(&old), &same, || unreachable!("a nickname was given"));
assert_eq!((b.id, b.name.as_str(), b.nickname.as_str()), (7, "Mine", "Other"));
assert_eq!(b.gateway_url, old.gateway_url);
assert_eq!(b.query, old.query);
assert_eq!(b.cached_server_icon, old.cached_server_icon);
// Another address: looked up again, for the new server.
let form = BookmarkForm { address: "new.example.test:9988".into(), ..same };
let b = bookmark_from_form(Some(&old), &form, || unreachable!("a nickname was given"));
assert_eq!(b.address, "new.example.test:9988");
assert!(b.cached_server_icon.is_none());
assert_eq!((b.identity, b.default_channel), (Some(2), Some("Lobby/Sub".into())));
assert_eq!(b.client_version.as_deref(), Some("linux"));
assert_eq!(b.gateway_url, None);
let q = b.query.unwrap();
assert_eq!(
(q.transport, q.host.as_str(), q.port),
(QueryTransport::Raw, "q.example.test", 10011)
);
assert_eq!(q.server_port, Some(9988));
assert_eq!((b.gateway_url, b.query), (None, None));
}
#[test]
+2 -7
View File
@@ -240,11 +240,6 @@ export struct BookmarkForm {
address: string,
nickname: string,
server-password: string,
gateway-url: string,
query-transport: string,
query-addr: string,
query-user: string,
query-password: string,
}
// A stream on the server, ours first: a stream can be watched from any
@@ -853,8 +848,9 @@ export global Bridge {
in property <int> own-channel-banner-mode;
in property <bool> voice-connected;
in property <bool> voice-connecting;
// Presence without joining (gateway or query), started when the server
// is selected.
in property <bool> observing;
in property <bool> can-observe;
in property <bool> input-muted;
in property <bool> output-muted;
in property <bool> transmitting;
@@ -945,7 +941,6 @@ export global Bridge {
callback search(string);
callback connect-voice();
callback disconnect-voice();
callback toggle-observe();
callback join-channel(int);
callback open-channel-chat(int);
callback toggle-collapse(int);
+5 -14
View File
@@ -1,5 +1,6 @@
// The server's sidebar: the server card, connect and observe, and the
// channel tree with its clients.
// The server's sidebar: the server card, connect, and the channel tree
// with its clients. Selecting a server observes it invisibly (through its
// gateway) on its own, so there is no button for it.
import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint";
@@ -82,14 +83,11 @@ export component ServerHeader inherits Rectangle {
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();
}
@@ -97,7 +95,7 @@ export component ServerHeader inherits Rectangle {
}
}
// Connect and observe while not connected.
// Connect while not connected.
export component ConnectActions inherits HorizontalLayout {
spacing: Theme.space-3;
Button {
@@ -108,13 +106,6 @@ export component ConnectActions inherits HorizontalLayout {
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.
@@ -352,7 +343,7 @@ export component ChannelTree inherits VerticalLayout {
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.");
text: Bridge.current-server < 0 ? @tr("No server yet.") : Bridge.observing ? @tr("Loading the channels…") : @tr("Connect to see the channels.");
color: Theme.text-muted;
font-size: Theme.font-sm;
wrap: word-wrap;
+5 -41
View File
@@ -26,11 +26,13 @@ export component BookmarkDialog inherits Modal {
// The fields beyond address and password: shown when editing.
property <bool> advanced: form.id >= 0;
title: join ? @tr("Join a server") : form.id < 0 ? @tr("Add server") : @tr("Edit server");
subtitle: @tr("Only the address is needed; Voelin finds the rest.");
// The gateway (presence and chat without joining) is found from the
// address: DNS SRV records, else the gateway's own well-known URL.
subtitle: @tr("Only the address is needed; Voelin finds the rest, including the server's gateway.");
icon: Icons.server;
card-width: 560px;
// Fits the address and password (two lines more on a phone).
card-height: advanced ? 720px : Nav.narrow ? 360px : 330px;
card-height: advanced ? 500px : Nav.narrow ? 360px : 330px;
dismissed => { done(); }
ScrollView {
vertical-stretch: 1;
@@ -57,7 +59,7 @@ export component BookmarkDialog inherits Modal {
clicked => { root.advanced = !root.advanced; }
}
Text {
text: @tr("Name, nickname, gateway, ServerQuery");
text: @tr("Name, nickname");
color: Theme.text-muted;
font-size: Theme.font-sm;
vertical-alignment: center;
@@ -77,44 +79,6 @@ export component BookmarkDialog inherits Modal {
hint: @tr("Empty: the nickname of your identity.");
TextField { text <=> form.nickname; label: @tr("Nickname"); icon: Icons.user; }
}
Text {
text: @tr("Invisible presence and chat without joining");
font-weight: Theme.weight-semibold;
color: Theme.text;
wrap: word-wrap;
}
Field {
label: @tr("Gateway URL");
hint: @tr("Empty: looked up in DNS, as published by the server's admin.");
TextField { text <=> form.gateway-url; placeholder: @tr("Found automatically"); label: @tr("Gateway URL"); }
}
HorizontalLayout {
spacing: Theme.space-4;
Field {
label: @tr("Query transport");
Select {
model: ["none", "ssh", "raw", "http"];
current-value <=> form.query-transport;
current-index: form.query-transport == "ssh" ? 1 : form.query-transport == "raw" ? 2 : form.query-transport == "http" ? 3 : 0;
label: @tr("Query transport");
}
}
Field {
label: @tr("Query address");
TextField { text <=> form.query-addr; placeholder: "ts.example.org:10022"; label: @tr("Query address"); }
}
}
HorizontalLayout {
spacing: Theme.space-4;
Field {
label: @tr("Query login");
TextField { text <=> form.query-user; label: @tr("Query login"); }
}
Field {
label: @tr("Query password");
TextField { text <=> form.query-password; input-type: InputType.password; label: @tr("Query password"); }
}
}
}
}
}
+1 -1
View File
@@ -407,7 +407,7 @@ export component MembersPanel inherits VerticalLayout {
padding-left: Theme.space-5;
padding-right: Theme.space-5;
Text {
text: @tr("Connect or observe to see who is here.");
text: Bridge.observing ? @tr("Loading who is here…") : @tr("Connect to see who is here.");
color: Theme.text-muted;
font-size: Theme.font-sm;
wrap: word-wrap;