ui: one dialog to add a server, with Save and Connect

Join a Server and Add a Server were the same dialog with other buttons,
and Join saved the server in Slint and then connected the one shown: when
saving failed, that was the server shown before. The dialog now has
Cancel, Save and Connect (also Enter in the address or password field).
Connect goes through Bridge.save-and-connect, which connects only the
server it saved (vm::servers::connect_to); it is hidden while the server
has voice, and Save is the main button then. On a phone Delete shows only
its icon, so the four buttons fit.

BookmarkForm carries a channel, its password and a privilege key for the
links to come: the dialog shows "Joins <channel>" and "This link grants a
server group", Connect connects into that channel, and connect_voice_to
passes the key on. Nav.join-server is gone; the dev switch join opens the
same dialog as bookmark. "Add server" reads "Add a server" everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
Claude committed 2026-10-07 11:12:37 +00:00
1 parent 4940966538
commit 95d86af627
14 files changed
+275 -70

No files matched your search

+2 -1
View File
@@ -47,8 +47,9 @@ pub(super) fn wire(ui: &MainWindow) {
});
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));
with_app(|app| app.save_bookmark(&form));
});
bridge.on_save_and_connect(|form| with_app(|app| app.save_and_connect(&form)).unwrap_or(false));
bridge.on_delete_bookmark(|id| {
with_app(|app| app.delete_bookmark(id as i64));
});
+6 -6
View File
@@ -14,7 +14,7 @@
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
//! `server` (`server:chat`: its server chat), `settings[:<section>]`
//! (voice, keybinds, streaming, privacy, appearance, or 0-4), `about`,
//! `share`, `bookmark` (add a server;
//! `share`, `bookmark` (add a server, also `join`;
//! `bookmark:edit` the current one, Advanced open),
//! `emoji` (the picker), `client` (the volume dialog of the first other
//! client once connected), `panel` / `no-panel` (the members panel),
@@ -38,9 +38,9 @@
//! `tab:<home|servers|chat|activity|you>` (phone layout); `friends[:<uid>]`,
//! `messages[:<uid>]` (a private chat), `inbox` (offline messages),
//! `library`, `events`, `event-form`, `search[:<text>]`,
//! `notifications` (the bell), `join` (join by address), `offline` (an
//! offline message), `picture` (a chat picture opened large), `camera`
//! (the settings' camera preview); settings sections also `account`,
//! `notifications` (the bell), `offline` (an offline message), `picture`
//! (a chat picture opened large), `camera` (the settings' camera
//! preview); settings sections also `account`,
//! `profiles` (also `identities`), `devices`, `notifications`,
//! `integrations`, `advanced` (5-10);
//! `studio[:<what>]`: the Stream Studio (with `VOELIN_DEMO_UI` a demo
@@ -245,7 +245,8 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
nav.invoke_edit_server(id as i32);
}
}
"bookmark" => nav.invoke_add_server(),
// `join`: the same dialog (Join a server was one of its own).
"bookmark" | "join" => nav.invoke_add_server(),
"emoji" => nav.set_emoji_open(true),
"panel" => nav.set_right_panel_open(true),
"no-panel" => nav.set_right_panel_open(false),
@@ -327,7 +328,6 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
"event-form" => nav.invoke_create_event(),
"search" => nav.invoke_open_search(arg.into()),
"notifications" => nav.set_notifications_open(true),
"join" => nav.invoke_join_server(),
"offline" => nav.invoke_write_offline("demo-ari".into(), "Ari".into()),
"picture" => {
let picture = demo_picture(1280, 720, 16);
+30 -18
View File
@@ -1,7 +1,7 @@
//! Servers: bookmarks, connecting and observing, the rail, the sidebar's
//! server card and the channel tree.
use slint::{ComponentHandle, SharedString};
use slint::ComponentHandle;
use tracing::{info, warn};
use voelin_core::identity::LaunchImport;
use voelin_core::{Command, JoinFailure, ObserveState, Source, VoiceOptions, VoiceState};
@@ -86,15 +86,17 @@ impl App {
pub(crate) fn connect_voice(&mut self) {
let channel =
self.current.and_then(|id| self.bookmark(id)).and_then(|b| b.default_channel.clone());
self.connect_voice_to(channel, None);
self.connect_voice_to(channel, None, None);
}
/// Connect the current server with voice, into `channel` (a path, or
/// `/<id>`, with its password) if given; whether it was asked for.
/// `/<id>`, with its password) if given, with a privilege key if given;
/// whether it was asked for.
pub(crate) fn connect_voice_to(
&mut self,
channel: Option<String>,
channel_password: Option<String>,
token: Option<String>,
) -> bool {
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return false };
if self.demo_ui {
@@ -114,6 +116,7 @@ impl App {
options.server_password = self.secrets.get(&b.server_password_key()).ok().flatten();
options.channel = channel;
options.channel_password = channel_password;
options.token = token;
options.audio = true;
options.stream_peer = self.video.peer_config(options.stream_peer);
self.engine
@@ -269,22 +272,16 @@ impl App {
..Default::default()
};
};
let secret = |key: String| -> SharedString {
self.secrets.get(&key).ok().flatten().unwrap_or_default().into()
};
BookmarkForm {
id: b.id as i32,
// Named by its address: empty, so a new address names it again.
name: if b.name == b.address { SharedString::new() } else { b.name.clone().into() },
address: b.address.clone().into(),
nickname: b.nickname.clone().into(),
server_password: secret(b.server_password_key()),
}
let password = self.secrets.get(&b.server_password_key()).ok().flatten();
let state = self.sessions.get(&b.id).map(|view| &view.state);
vm::servers::form(b, state, password.as_deref().unwrap_or_default())
}
pub(crate) fn save_bookmark(&mut self, form: BookmarkForm) {
/// Save the server dialog's server, and show it; its id, none when it
/// could not be saved (the toast says why).
pub(crate) fn save_bookmark(&mut self, form: &BookmarkForm) -> Option<i64> {
let old = self.bookmark(form.id as i64).cloned();
let mut bookmark = bookmark_from_form(old.as_ref(), &form, || self.default_nickname());
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 {
@@ -292,7 +289,7 @@ impl App {
};
if let Err(e) = result {
self.set_status(format!("Could not save: {e}"));
return;
return None;
}
let key = bookmark.server_password_key();
let result = if form.server_password.is_empty() {
@@ -317,6 +314,21 @@ impl App {
}
self.bookmarks = self.store.bookmarks().unwrap_or_default();
self.select_server(bookmark.id);
Some(bookmark.id)
}
/// The server dialog's Connect: save the server, then connect it with
/// voice, into the channel of the link that filled the form if one did
/// ([`vm::servers::connect_to`]). Only once saved: connecting what is
/// shown after a failed save would connect the server shown before.
/// Whether it was saved.
pub(crate) fn save_and_connect(&mut self, form: &BookmarkForm) -> bool {
let saved = self.save_bookmark(form);
let Some(to) = vm::servers::connect_to(form, saved.and_then(|id| self.bookmark(id))) else {
return false;
};
self.connect_voice_to(to.channel, to.channel_password, to.token);
true
}
pub(crate) fn delete_bookmark(&mut self, id: i64) {
@@ -589,7 +601,7 @@ impl App {
}
// By id: by its name the server finds only a top-level channel (a
// subchannel's name connects into the default channel).
if self.connect_voice_to(Some(format!("/{channel}")), password)
if self.connect_voice_to(Some(format!("/{channel}")), password, None)
&& let Some(view) = self.sessions.get_mut(&session)
{
view.join_after_connect = Some(channel);
+120 -2
View File
@@ -1,10 +1,11 @@
//! The server rail, and joining a channel.
//! The server rail, the server dialog, and joining a channel.
use slint::SharedString;
use voelin_core::{ObserveState, SessionState, VoiceState};
use voelin_model::{ChannelId, ChannelInfo};
use voelin_store::Bookmark;
use crate::app::ServerItem;
use crate::app::{BookmarkForm, ServerItem};
use crate::vm::avatar;
/// Restore a known server icon before any session exists. A missing/evicted
@@ -54,6 +55,54 @@ pub fn item(
}
}
/// The server dialog's form for `bookmark`, with its stored password:
/// `connected` while `state` has voice, which hides Connect. A server still
/// named by its address shows no name, so a new address names it again.
pub fn form(
bookmark: &Bookmark,
state: Option<&SessionState>,
server_password: &str,
) -> BookmarkForm {
BookmarkForm {
id: bookmark.id as i32,
name: if bookmark.name == bookmark.address {
SharedString::new()
} else {
bookmark.name.clone().into()
},
address: bookmark.address.clone().into(),
nickname: bookmark.nickname.clone().into(),
server_password: server_password.into(),
connected: state.is_some_and(|s| s.voice == VoiceState::Connected),
..Default::default()
}
}
/// Where the server dialog's Connect goes ([`connect_to`]).
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ConnectTo {
/// A channel path, or `/<id>`.
pub channel: Option<String>,
pub channel_password: Option<String>,
/// A privilege key.
pub token: Option<String>,
}
/// What the server dialog's Connect connects with, once the form was saved
/// as `saved` (none: saving failed, and nothing connects): the form's
/// channel (a link's) with its password, else the server's default
/// channel; and the link's privilege key.
pub fn connect_to(form: &BookmarkForm, saved: Option<&Bookmark>) -> Option<ConnectTo> {
let saved = saved?;
let given = |text: &SharedString| Some(text.to_string()).filter(|t| !t.is_empty());
let channel = given(&form.channel);
Some(ConnectTo {
channel_password: channel.as_ref().and_then(|_| given(&form.channel_password)),
channel: channel.or_else(|| saved.default_channel.clone()),
token: given(&form.token),
})
}
/// A `ts3server://` link that joins the channel at `path` (its names from
/// the top) on the server at `address` (`host`, `host:port` or
/// `[v6]:port`), as TeamSpeak clients open them.
@@ -179,6 +228,75 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}
#[test]
fn connect_shows_only_without_voice() {
let b = Bookmark {
id: 3,
name: "ts.example.test".into(),
address: "ts.example.test".into(),
nickname: "Nova".into(),
..Default::default()
};
let mut state = SessionState::default();
let f = form(&b, None, "pw");
assert_eq!((f.id, f.name.as_str(), f.address.as_str()), (3, "", "ts.example.test"));
assert_eq!((f.nickname.as_str(), f.server_password.as_str()), ("Nova", "pw"));
assert!(!f.connected);
for (voice, connected) in [
(VoiceState::Disconnected, false),
// Connect again with another address.
(VoiceState::Connecting, false),
(VoiceState::Connected, true),
] {
state.voice = voice;
assert_eq!(form(&b, Some(&state), "").connected, connected, "{voice:?}");
}
// Observing is not voice.
state.voice = VoiceState::Disconnected;
state.observe = ObserveState::Observing;
assert!(!form(&b, Some(&state), "").connected);
let named = Bookmark { name: "Nightfall".into(), ..b };
assert_eq!(form(&named, None, "").name.as_str(), "Nightfall");
}
#[test]
fn connect_only_what_was_saved() {
let saved = Bookmark { id: 3, default_channel: Some("Lobby".into()), ..Default::default() };
let plain = BookmarkForm { address: "ts.example.test".into(), ..Default::default() };
// Saving failed: nothing connects (not the server shown before).
assert_eq!(connect_to(&plain, None), None);
assert_eq!(
connect_to(&plain, Some(&saved)),
Some(ConnectTo { channel: Some("Lobby".into()), ..Default::default() })
);
// A link's channel, its password and privilege key.
let link = BookmarkForm {
channel: "Gaming/Raid Night".into(),
channel_password: "raid".into(),
token: "key".into(),
..plain.clone()
};
assert_eq!(connect_to(&link, None), None);
assert_eq!(
connect_to(&link, Some(&saved)),
Some(ConnectTo {
channel: Some("Gaming/Raid Night".into()),
channel_password: Some("raid".into()),
token: Some("key".into()),
})
);
// A password goes only with the link's channel.
let token = BookmarkForm { channel_password: "raid".into(), token: "key".into(), ..plain };
assert_eq!(
connect_to(&token, Some(&saved)),
Some(ConnectTo {
channel: Some("Lobby".into()),
channel_password: None,
token: Some("key".into()),
})
);
}
#[test]
fn invite_links() {
assert_eq!(
-1
View File
@@ -394,7 +394,6 @@ export component MainWindow inherits Window {
if !Bridge.myts.prompt && (Nav.bookmark-open): BookmarkDialog {
form <=> Nav.bookmark-form;
join: Nav.join-open;
done => { Nav.bookmark-open = false; }
}
+13
View File
@@ -287,12 +287,21 @@ export struct TopicItem {
archived: bool,
}
// The server dialog: a bookmark (id -1: a new one) and, from a link, where
// Connect goes.
export struct BookmarkForm {
id: int,
name: string,
address: string,
nickname: string,
server-password: string,
// The server has voice: no Connect.
connected: bool,
// From a link, not stored with the server: the channel to join (a
// path, or /<id>), its password and a privilege key.
channel: string,
channel-password: string,
token: string,
}
// A stream on the server, ours first: a stream can be watched from any
@@ -1058,6 +1067,10 @@ export global Bridge {
callback push-to-talk(bool);
callback edit-bookmark(int) -> BookmarkForm;
callback save-bookmark(BookmarkForm);
// The server dialog's Connect: save, then connect with voice (into the
// form's channel, if any); false when saving failed, and nothing
// connects.
callback save-and-connect(BookmarkForm) -> bool;
callback delete-bookmark(int);
callback open-share() -> ShareForm;
+1 -11
View File
@@ -102,8 +102,7 @@ export global Nav {
// The bell's panel, the search (Ctrl+K) and its selected result, a
// picture opened from the chat, the event and offline message forms,
// the friends page's tab, the direct messages' tab, the add-server
// dialog in "join" mode (connect once saved).
// the friends page's tab, the direct messages' tab.
in-out property <bool> notifications-open;
in-out property <bool> search-open;
in-out property <string> search-text;
@@ -117,7 +116,6 @@ export global Nav {
in-out property <OfflineForm> offline-form;
in-out property <int> friends-tab;
in-out property <int> dm-tab;
in-out property <bool> join-open;
// Text for the clipboard, and a counter that changes with every copy:
// MainWindow copies it through a hidden text field (`copy` below).
@@ -232,12 +230,6 @@ export global Nav {
offline-form-open = true;
}
public function join-server() {
bookmark-form = Bridge.edit-bookmark(-1);
join-open = true;
bookmark-open = true;
}
// The members panel of the current server.
public function show-members() {
show(Page.server);
@@ -262,13 +254,11 @@ export global Nav {
public function add-server() {
bookmark-form = Bridge.edit-bookmark(-1);
join-open = false;
bookmark-open = true;
}
public function edit-server(id: int) {
bookmark-form = Bridge.edit-bookmark(id);
join-open = false;
bookmark-open = true;
}
+1 -1
View File
@@ -83,7 +83,7 @@ export component ServerHeader inherits Rectangle {
menu := PopupMenu {
entries: [
{ text: @tr("Edit server"), icon: Icons.pencil, enabled: Bridge.current-server >= 0 },
{ text: @tr("Add server"), icon: Icons.plus, enabled: true, separator: true },
{ text: @tr("Add a server"), icon: Icons.plus, enabled: true, separator: true },
];
activated(i) => {
if i == 0 {
+78 -21
View File
@@ -17,24 +17,53 @@ component Footer inherits HorizontalLayout {
}
// Add or edit a server: its address and, if it has one, its password; the
// rest under Advanced (name, nickname, gateway, ServerQuery), which Voelin
// fills in itself when left empty.
// rest under Advanced (name, nickname), which Voelin fills in itself when
// left empty. Save keeps it; Connect keeps it and connects, into the channel
// of the link that opened the dialog if one did.
export component BookmarkDialog inherits Modal {
in-out property <BookmarkForm> form;
// Join by address: connect once saved.
in property <bool> join;
callback done();
// 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");
title: form.id < 0 ? @tr("Add a server") : @tr("Edit server");
// The rest includes the gateway (presence and chat without joining),
// found from the address: DNS SRV records, else its well-known URL.
subtitle: @tr("Only the address is needed; Voelin finds the rest.");
icon: Icons.server;
card-width: 560px;
// Fits the address and password (two lines more on a phone).
card-height: advanced ? 500px : Nav.narrow ? 360px : 330px;
// Fits the address and password (two lines more on a phone), and a
// link's channel and privilege key.
card-height: (advanced ? 500px : Nav.narrow ? 360px : 330px)
+ (form.channel != "" ? 48px : 0px) + (form.token != "" ? 48px : 0px);
dismissed => { done(); }
function save() {
if form.address != "" {
Bridge.save-bookmark(form);
done();
}
}
// Nothing connects unless the server was saved (a failure is told in
// the toast once the dialog is gone).
function connect() {
if form.address != "" {
if Bridge.save-and-connect(form) {
Nav.show(Page.server);
}
done();
}
}
// Enter: Connect, or Save while the server has voice.
function submit() {
if form.connected {
save();
} else {
connect();
}
}
ScrollView {
vertical-stretch: 1;
VerticalLayout {
@@ -44,11 +73,34 @@ export component BookmarkDialog inherits Modal {
Field {
label: @tr("Address");
hint: @tr("Host name, IP address or server nickname; a port only if the server needs one.");
TextField { text <=> form.address; placeholder: "ts.example.org"; label: @tr("Address"); icon: Icons.globe; }
TextField {
text <=> form.address;
placeholder: "ts.example.org";
label: @tr("Address");
icon: Icons.globe;
accepted => { root.submit(); }
}
}
Field {
label: @tr("Server password (optional)");
TextField { text <=> form.server-password; input-type: InputType.password; label: @tr("Server password"); icon: Icons.lock; }
TextField {
text <=> form.server-password;
input-type: InputType.password;
label: @tr("Server password");
icon: Icons.lock;
accepted => { root.submit(); }
}
}
// A link's: where Connect goes, and what it brings.
if form.channel != "": Banner {
icon: Icons.channel;
tone: Theme.info;
text: @tr("Joins {}", form.channel);
}
if form.token != "": Banner {
icon: Icons.key-round;
tone: Theme.info;
text: @tr("This link grants a server group");
}
HorizontalLayout {
spacing: Theme.space-3;
@@ -83,11 +135,16 @@ export component BookmarkDialog inherits Modal {
}
}
}
Footer {
// Not a Footer: its `alignment: end` gives the spacer no width, which
// put Delete right next to Cancel.
HorizontalLayout {
spacing: Theme.space-3;
if form.id >= 0: Button {
kind: ButtonKind.danger;
icon: Icons.trash-2;
text: @tr("Delete");
// Only the icon on a phone, where four buttons do not fit.
text: Nav.narrow ? "" : @tr("Delete");
accessible-label: @tr("Delete");
clicked => {
Bridge.delete-bookmark(form.id);
done();
@@ -98,18 +155,18 @@ export component BookmarkDialog inherits Modal {
text: @tr("Cancel");
clicked => { done(); }
}
// The main action while the server has voice (no Connect then).
Button {
kind: ButtonKind.primary;
text: root.join ? @tr("Join") : form.id < 0 ? @tr("Add") : @tr("Save");
kind: form.connected ? ButtonKind.primary : ButtonKind.secondary;
text: @tr("Save");
enabled: form.address != "";
clicked => {
Bridge.save-bookmark(form);
if root.join {
Bridge.connect-voice();
Nav.show(Page.server);
}
done();
}
clicked => { root.save(); }
}
if !form.connected: Button {
kind: ButtonKind.primary;
text: @tr("Connect");
enabled: form.address != "";
clicked => { root.connect(); }
}
}
}
+2 -2
View File
@@ -168,7 +168,7 @@ export component HomeNav inherits VerticalLayout {
QuickNav {
icon: Icons.log-in;
text: @tr("Join a Server");
clicked => { Nav.join-server(); }
clicked => { Nav.add-server(); }
}
QuickNav {
icon: Icons.user-plus;
@@ -1279,7 +1279,7 @@ export component HomeAside inherits Rectangle {
icon: Icons.log-in;
title: @tr("Join a Server");
subtitle: @tr("Enter an address");
clicked => { Nav.join-server(); }
clicked => { Nav.add-server(); }
}
QuickAction {
icon: Icons.bookmark;
+1 -1
View File
@@ -60,7 +60,7 @@ export component MobileServers inherits VerticalLayout {
}
IconButton {
icon: Icons.plus;
label: @tr("Add server");
label: @tr("Add a server");
round: true;
filled: true;
size: 46px;
+1 -1
View File
@@ -139,7 +139,7 @@ export component ServerRail inherits Rectangle {
padding-top: Theme.space-2;
IconButton {
icon: Icons.plus;
label: @tr("Add server");
label: @tr("Add a server");
round: true;
filled: true;
size: 46px;