Merge the development branch: add a server by its address, TSDNS, gateway DNS
Both sides kept. From the development branch: the add-server dialog asks for the address and an optional password (the rest under Advanced when editing), servers are found through TSDNS and their gateways in DNS, wss:// gateways, the official client's identities imported on every start, and a bookmark built from the form over the old one. The dialog keeps this wave's join mode for Home's "Join a Server": its title says so, the button reads Join and connects once saved; adding and editing read as on the development branch. Saving takes the development branch's bookmark_from_form, which keeps the bookmark's identity as this wave's code did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
356bb0c6ac
21 files changed
+1294
-283
No files matched your search
@@ -19,7 +19,8 @@ use tokio::runtime::Runtime;
|
||||
use tracing::warn;
|
||||
use voelin_core::media::decoder_preference;
|
||||
use voelin_core::settings::{
|
||||
AUDIO, CRASH_REPORTS, STREAM_DECODER_BACKEND, STREAM_HARDWARE_DECODING, Settings,
|
||||
AUDIO, CRASH_REPORTS, IDENTITY_IMPORT, STREAM_DECODER_BACKEND, STREAM_HARDWARE_DECODING,
|
||||
Settings,
|
||||
};
|
||||
use voelin_core::stream::StreamInfo;
|
||||
use voelin_core::{
|
||||
@@ -560,16 +561,30 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
Ok(history) => engine.send(Command::AttachHistory(history)),
|
||||
Err(e) => warn!(%e, "chat history is not stored this time"),
|
||||
}
|
||||
let prefs = open_settings(&dir, &options.setting_overrides);
|
||||
let switches = crate::dev::Switches::from_env();
|
||||
// New identities of the official TeamSpeak clients, on every start (not
|
||||
// with the sample data of VOELIN_DEMO_UI); with none of our own yet, the
|
||||
// client's default identity becomes ours.
|
||||
let had_identity = !store.identities()?.is_empty();
|
||||
let imported = if prefs.get(&IDENTITY_IMPORT) && !switches.demo_ui {
|
||||
voelin_core::identity::import_new(&store, &voelin_core::identity::discover())
|
||||
.unwrap_or_else(|e| {
|
||||
warn!(%e, "could not import TeamSpeak identities");
|
||||
Vec::new()
|
||||
})
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
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)?;
|
||||
store.add_identity(crate::servers::CREATED_IDENTITY, &identity)?;
|
||||
identity
|
||||
}
|
||||
};
|
||||
let prefs = open_settings(&dir, &options.setting_overrides);
|
||||
engine.send(Command::AttachSettings(prefs.clone()));
|
||||
let mut settings: UiSettings = (*prefs.get_arc(&UI)).clone();
|
||||
settings.crash_reports = prefs.get(&CRASH_REPORTS);
|
||||
@@ -600,7 +615,6 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
}
|
||||
let mut video = Video::new(&dir, settings.openh264);
|
||||
video.set_decoder_preference(decoder_preference(&prefs));
|
||||
let switches = crate::dev::Switches::from_env();
|
||||
let app = App {
|
||||
ui: ui.as_weak(),
|
||||
store,
|
||||
@@ -660,6 +674,9 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
if app.demo {
|
||||
app.start_demo();
|
||||
}
|
||||
if let Some(text) = crate::servers::imported_status(&imported, had_identity) {
|
||||
app.set_status(text);
|
||||
}
|
||||
});
|
||||
|
||||
// Engine events -> UI thread, until the event loop is gone.
|
||||
@@ -833,6 +850,7 @@ impl App {
|
||||
}
|
||||
Event::ServerInfo { session, name, flavor, capabilities } => {
|
||||
self.sessions.entry(session as i64).or_default().capabilities = capabilities;
|
||||
self.adopt_server_name(session as i64, &name);
|
||||
if self.current == Some(session as i64) {
|
||||
let kind = match flavor {
|
||||
voelin_model::ServerFlavor::Ts3(v) => format!("TeamSpeak 3 {v}"),
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer.
|
||||
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
|
||||
//! `server`, `settings[:<section>]` (voice, keybinds, streaming, privacy,
|
||||
//! appearance, or 0-4), `about`, `share`, `bookmark` (add a server),
|
||||
//! appearance, or 0-4), `about`, `share`, `bookmark` (add a server;
|
||||
//! `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),
|
||||
//! `voice` (the voice channel view; on the phone its own screen),
|
||||
@@ -177,6 +178,12 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
with_app(|app| app.demo_share());
|
||||
}
|
||||
}
|
||||
// The current server's dialog, Advanced open.
|
||||
"bookmark" if arg == "edit" => {
|
||||
if let Some(id) = with_app(|app| app.current).flatten() {
|
||||
nav.invoke_edit_server(id as i32);
|
||||
}
|
||||
}
|
||||
"bookmark" => nav.invoke_add_server(),
|
||||
"emoji" => nav.set_emoji_open(true),
|
||||
"panel" => nav.set_right_panel_open(true),
|
||||
|
||||
+233
-46
@@ -3,12 +3,87 @@
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
use tracing::warn;
|
||||
use voelin_core::identity::Found;
|
||||
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
|
||||
use voelin_store::{Bookmark, QueryConfig, QueryTransport};
|
||||
|
||||
use crate::app::{App, BookmarkForm, Bridge};
|
||||
use crate::app::{App, BookmarkForm, Bridge, later};
|
||||
use crate::vm;
|
||||
|
||||
/// The name of the identity the app creates when it has none.
|
||||
pub(crate) const CREATED_IDENTITY: &str = "Default";
|
||||
|
||||
/// What to tell the user about the identities imported from the official
|
||||
/// clients at start ([`voelin_core::identity::import_new`]), if any.
|
||||
/// `had_identity`: we had one before, so it stays the default.
|
||||
pub(crate) fn imported_status(imported: &[Found], had_identity: bool) -> Option<String> {
|
||||
let first = imported.first()?;
|
||||
let n = imported.len();
|
||||
let names = imported.iter().map(|f| f.nickname.as_str()).collect::<Vec<_>>().join(", ");
|
||||
Some(match (had_identity, n) {
|
||||
(true, 1) => format!("Imported the identity \u{201c}{names}\u{201d} from TeamSpeak"),
|
||||
(true, _) => format!("Imported {n} identities from TeamSpeak: {names}"),
|
||||
(false, 1) => format!("Using your TeamSpeak identity \u{201c}{names}\u{201d}"),
|
||||
(false, _) => format!(
|
||||
"Using your TeamSpeak identity \u{201c}{}\u{201d} ({n} imported: {names})",
|
||||
first.nickname
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
/// The bookmark the form describes, over `old` (what the form does not show,
|
||||
/// 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.
|
||||
fn bookmark_from_form(
|
||||
old: Option<&Bookmark>,
|
||||
form: &BookmarkForm,
|
||||
default_nickname: impl FnOnce() -> String,
|
||||
) -> Bookmark {
|
||||
let mut bookmark = old.cloned().unwrap_or_default();
|
||||
bookmark.id = form.id as i64;
|
||||
bookmark.address = form.address.trim().to_string();
|
||||
bookmark.name = match form.name.trim() {
|
||||
"" => bookmark.address.clone(),
|
||||
name => name.to_string(),
|
||||
};
|
||||
bookmark.nickname = match form.nickname.trim() {
|
||||
"" => 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
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(crate) fn connect_voice(&mut self) {
|
||||
let channel =
|
||||
@@ -32,6 +107,77 @@ impl App {
|
||||
self.engine
|
||||
.send(Command::ConnectVoice { session: b.id as u64, options: Box::new(options) });
|
||||
self.set_status(format!("Connecting to {}…", b.address));
|
||||
// The admin may have published the gateway since it was added.
|
||||
self.discover_gateway(b.id);
|
||||
}
|
||||
|
||||
/// The nickname a new server gets: the default identity's (one imported
|
||||
/// from TeamSpeak keeps the nickname used there), else the system user's.
|
||||
pub(crate) fn default_nickname(&self) -> String {
|
||||
self.store
|
||||
.identities()
|
||||
.ok()
|
||||
.and_then(|identities| identities.into_iter().next())
|
||||
.map(|identity| identity.name)
|
||||
.filter(|name| {
|
||||
![CREATED_IDENTITY, voelin_core::identity::DEFAULT_NICKNAME]
|
||||
.contains(&name.as_str())
|
||||
})
|
||||
.or_else(|| std::env::var("USER").or_else(|_| std::env::var("USERNAME")).ok())
|
||||
// Servers refuse an empty nickname (Android has no user name).
|
||||
.filter(|name| !name.trim().is_empty())
|
||||
.unwrap_or_else(|| "Voelin user".to_owned())
|
||||
}
|
||||
|
||||
/// Look up the gateway of a server that has none in DNS
|
||||
/// ([`voelin_core::discover`]); one found is kept as if typed.
|
||||
pub(crate) fn discover_gateway(&self, id: i64) {
|
||||
let Some(b) = self.bookmark(id).filter(|b| b.gateway_url.is_none() && !self.demo_ui) else {
|
||||
return;
|
||||
};
|
||||
let address = b.address.clone();
|
||||
self.engine.runtime().spawn(async move {
|
||||
if let Some(url) = voelin_core::discover::gateway(&address).await {
|
||||
later(move |app| app.gateway_found(id, &address, url));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A gateway was found for the server at `address`; it is kept unless
|
||||
/// the server changed meanwhile.
|
||||
fn gateway_found(&mut self, id: i64, address: &str, url: String) {
|
||||
let Some(b) = self
|
||||
.bookmarks
|
||||
.iter_mut()
|
||||
.find(|b| b.id == id && b.address == address && b.gateway_url.is_none())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
b.gateway_url = Some(url.clone());
|
||||
let name = b.name.clone();
|
||||
if let Err(e) = self.store.update_bookmark(b) {
|
||||
warn!(%e, "could not keep the gateway found");
|
||||
return;
|
||||
}
|
||||
self.set_status(format!("Found the gateway of {name}: {url}"));
|
||||
self.refresh_toolbar();
|
||||
}
|
||||
|
||||
/// The server told its name: a server still named by its address takes
|
||||
/// it, so the address is all a user has to type.
|
||||
pub(crate) fn adopt_server_name(&mut self, id: i64, name: &str) {
|
||||
let Some(b) = self.bookmarks.iter_mut().find(|b| b.id == id && b.name == b.address) else {
|
||||
return;
|
||||
};
|
||||
if name.trim().is_empty() || self.demo_ui {
|
||||
return;
|
||||
}
|
||||
b.name = name.trim().to_owned();
|
||||
if let Err(e) = self.store.update_bookmark(b) {
|
||||
warn!(%e, "could not name the server");
|
||||
}
|
||||
self.refresh_servers();
|
||||
self.refresh_toolbar();
|
||||
}
|
||||
|
||||
pub(crate) fn toggle_observe(&mut self) {
|
||||
@@ -79,7 +225,7 @@ impl App {
|
||||
let Some(b) = self.bookmark(id) else {
|
||||
return BookmarkForm {
|
||||
id: -1,
|
||||
nickname: std::env::var("USER").unwrap_or_default().into(),
|
||||
nickname: self.default_nickname().into(),
|
||||
query_transport: "none".into(),
|
||||
query_user: "serveradmin".into(),
|
||||
..Default::default()
|
||||
@@ -102,7 +248,8 @@ impl App {
|
||||
};
|
||||
BookmarkForm {
|
||||
id: b.id as i32,
|
||||
name: b.name.clone().into(),
|
||||
// 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()),
|
||||
@@ -115,49 +262,8 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) 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: self.bookmark(form.id as i64).and_then(|b| b.identity),
|
||||
default_channel: None,
|
||||
gateway_url: Some(form.gateway_url.to_string()).filter(|u| !u.is_empty()),
|
||||
query,
|
||||
client_version: None,
|
||||
};
|
||||
let mut bookmark =
|
||||
bookmark_from_form(self.bookmark(form.id as i64), &form, || self.default_nickname());
|
||||
let result = if bookmark.id < 0 {
|
||||
self.store.add_bookmark(&bookmark).map(|id| bookmark.id = id)
|
||||
} else {
|
||||
@@ -183,6 +289,7 @@ impl App {
|
||||
self.current = Some(bookmark.id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.refresh_all();
|
||||
self.discover_gateway(bookmark.id);
|
||||
}
|
||||
|
||||
pub(crate) fn delete_bookmark(&mut self, id: i64) {
|
||||
@@ -368,3 +475,83 @@ impl App {
|
||||
self.refresh_tree();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[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 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");
|
||||
assert_eq!(
|
||||
(b.gateway_url, b.query, b.identity, b.default_channel),
|
||||
(None, None, None, None)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_keeps_what_the_form_does_not_show() {
|
||||
let old = Bookmark {
|
||||
id: 7,
|
||||
name: "Old".into(),
|
||||
address: "old.example.test".into(),
|
||||
nickname: "Me".into(),
|
||||
identity: Some(2),
|
||||
default_channel: Some("Lobby/Sub".into()),
|
||||
gateway_url: Some("ws://gw.example.test:7788/v1".into()),
|
||||
query: Some(QueryConfig { server_port: Some(9988), ..Default::default() }),
|
||||
client_version: Some("linux".into()),
|
||||
};
|
||||
let form = BookmarkForm {
|
||||
id: 7,
|
||||
name: "Mine".into(),
|
||||
address: "new.example.test:9988".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"));
|
||||
assert_eq!((b.id, b.name.as_str(), b.nickname.as_str()), (7, "Mine", "Other"));
|
||||
assert_eq!(b.address, "new.example.test:9988");
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_import_is_told_by_nickname() {
|
||||
let found = |nickname: &str| Found {
|
||||
nickname: nickname.into(),
|
||||
identity: tsclientlib::Identity::create(),
|
||||
source: "settings.db".into(),
|
||||
selected: false,
|
||||
};
|
||||
assert_eq!(imported_status(&[], false), None);
|
||||
assert_eq!(
|
||||
imported_status(&[found("Main")], false).unwrap(),
|
||||
"Using your TeamSpeak identity \u{201c}Main\u{201d}"
|
||||
);
|
||||
assert_eq!(
|
||||
imported_status(&[found("Main"), found("Alt")], true).unwrap(),
|
||||
"Imported 2 identities from TeamSpeak: Main, Alt"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user