voelin-ui-vm: the server sequences both front ends ran twice are one
The GPUI shell repeated the Slint crate's connect, observe, gateway lookup, save and remove of a server, its default nickname, its FallbackSecrets and its settings opening and key registration. They now live once and both front ends call them: - voelin_ui_vm::servers::sequence: connect_voice(_to), observe, discover_gateway, gateway_found, select_server, save_bookmark, save_and_connect, delete_bookmark, bookmark_form and default_nickname, as transitions over the state, the Cx and a Backing (the store, the secrets, the identity a connection uses). The commands, the status line and what to keep go out through the Update as for every other transition; a new field, Update::discover, asks the front end to look a gateway up (the thread hop stays with each front end: Later in GPUI, later() in Slint). stream_peer is the one input a front end gives (Slint's codecs; GPUI passes none). - voelin_ui_vm::settings::open_settings and register_keys; a front end adds its own key (ui.window, studio.ui) through a function it passes, so Slint's settings page still lists what it listed. - voelin_store::FallbackSecrets (feature keyring) and Store::identity_for. - voelin-ui: the methods of servers/bind.rs, open_settings and default_secrets call them, so their call sites are unchanged; host.rs gets transition_with and the discover arm of perform. voelin-gpui: AppState's methods and the Backend call them. What cannot move is named in docs/ui.md. voelin-ui-vm now depends on tracing (the sequences log as the copies did): one line of Cargo.lock, THIRD_PARTY_NOTICES.md unchanged (scripts/notices.sh --check clean), cargo deny check clean. The sequences have ten tests over a fake front end (commands, status, store, secrets, gateways), open_settings and Store::identity_for one each; the GPUI and Slint suites pass unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01bf128c58
commit
a77ccc0415
15 files changed
+1148
-578
No files matched your search
+12
-67
@@ -37,83 +37,28 @@ use crate::vm;
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
/// The settings service on the client database: the UI's keys registered,
|
||||
/// then a config file (`VOELIN_CONFIG`, else `<data dir>/config.toml` if it
|
||||
/// exists), `VOELIN_SETTING_*` variables and `overrides` below the stored
|
||||
/// values. Without the database the settings live in memory.
|
||||
/// The settings service on the client database
|
||||
/// ([`vm::settings::open_settings`], which the GPUI front end opens the same
|
||||
/// way): the UI's keys registered, with the Stream Studio's, then a config
|
||||
/// file (`VOELIN_CONFIG`, else `<data dir>/config.toml` if it exists),
|
||||
/// `VOELIN_SETTING_*` variables and `overrides` below the stored values.
|
||||
/// Without the database the settings live in memory.
|
||||
fn open_settings(dir: &Path, overrides: &[String]) -> Settings {
|
||||
let prefs = Settings::open(&dir.join("client.db")).unwrap_or_else(|e| {
|
||||
warn!(%e, "settings are not stored this time");
|
||||
Settings::in_memory()
|
||||
});
|
||||
prefs.register(&UI);
|
||||
prefs.register(&CLIENT_PLAYBACK);
|
||||
for key in appearance_keys() {
|
||||
prefs.register(key);
|
||||
}
|
||||
for key in crate::settings::page_keys() {
|
||||
prefs.register(key);
|
||||
}
|
||||
prefs.register(&crate::vm::studio::logic::STUDIO_UI);
|
||||
let config = std::env::var_os("VOELIN_CONFIG")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
|
||||
let mut errors = match config.map(|path| prefs.load_config_file(&path)) {
|
||||
Some(Ok(errors)) => errors,
|
||||
Some(Err(e)) => vec![e],
|
||||
None => Vec::new(),
|
||||
};
|
||||
errors.extend(prefs.apply_env(std::env::vars()));
|
||||
errors.extend(prefs.apply_overrides(overrides.iter().map(String::as_str)));
|
||||
for e in errors {
|
||||
warn!(%e, "setting ignored");
|
||||
}
|
||||
prefs
|
||||
}
|
||||
|
||||
/// Secrets in the OS keyring, or in memory when there is none (headless
|
||||
/// Linux without a Secret Service).
|
||||
#[cfg(not(target_os = "android"))]
|
||||
struct FallbackSecrets {
|
||||
keyring: voelin_store::KeyringSecrets,
|
||||
memory: MemorySecrets,
|
||||
vm::settings::open_settings(dir, overrides, |prefs| {
|
||||
prefs.register(&crate::vm::studio::logic::STUDIO_UI);
|
||||
})
|
||||
}
|
||||
|
||||
/// The secrets store when [`RunOptions::secrets`] is not given: the OS
|
||||
/// keyring on desktop, memory elsewhere.
|
||||
/// keyring on desktop (memory behind it where the keyring refuses: a headless
|
||||
/// Linux without a Secret Service), memory elsewhere.
|
||||
fn default_secrets() -> Box<dyn Secrets> {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
return Box::new(FallbackSecrets {
|
||||
keyring: voelin_store::KeyringSecrets::new("voelin"),
|
||||
memory: MemorySecrets::default(),
|
||||
});
|
||||
return Box::new(voelin_store::FallbackSecrets::new("voelin"));
|
||||
#[cfg(target_os = "android")]
|
||||
return Box::new(MemorySecrets::default());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
impl Secrets for FallbackSecrets {
|
||||
fn get(&self, key: &str) -> voelin_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) -> voelin_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) -> voelin_store::Result<()> {
|
||||
let _ = self.keyring.delete(key);
|
||||
self.memory.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
/// The lines of a chat as the chat view shows them.
|
||||
pub(crate) type ChatRows = Rows<vm::bridge::ChatLine>;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::settings::{CLIENT_PLAYBACK, UI_IMAGE_PREVIEW_KB};
|
||||
use crate::social::Social;
|
||||
use crate::studio::StudioState;
|
||||
use crate::vm::host::{Cx, Host, PasswordPrompt, Persist, Refresh, Update};
|
||||
use crate::vm::servers::sequence::Backing;
|
||||
|
||||
/// What the transitions ask while they run: the window, the store and the
|
||||
/// settings, borrowed from the app besides its state.
|
||||
@@ -87,6 +88,16 @@ impl App {
|
||||
pub(crate) fn with_social<R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut AppState, &mut Social, &SlintHost<'_>) -> R,
|
||||
) -> R {
|
||||
self.with_parts(|state, social, host, _| f(state, social, host))
|
||||
}
|
||||
|
||||
/// Run `f` with the state, the social state, the host and the
|
||||
/// [`Backing`] of the server sequences (the store, the secrets and the
|
||||
/// identity, borrowed from the app besides its state).
|
||||
fn with_parts<R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut AppState, &mut Social, &SlintHost<'_>, &Backing<'_>) -> R,
|
||||
) -> R {
|
||||
let host = SlintHost {
|
||||
demo_ui: self.demo_ui,
|
||||
@@ -99,7 +110,11 @@ impl App {
|
||||
prefs: &self.prefs,
|
||||
studio: &self.studio,
|
||||
};
|
||||
f(&mut self.state, &mut self.social, &host)
|
||||
let identity = |named| {
|
||||
voelin_core::ts::identity::to_blob(&self.store.identity_for(named, &self.identity))
|
||||
};
|
||||
let backing = Backing { store: &self.store, secrets: &*self.secrets, identity: &identity };
|
||||
f(&mut self.state, &mut self.social, &host, &backing)
|
||||
}
|
||||
|
||||
/// An engine event: what it does to the state is in `voelin-ui-vm`
|
||||
@@ -123,6 +138,22 @@ impl App {
|
||||
result
|
||||
}
|
||||
|
||||
/// Like [`App::transition`], for a sequence that also reads and writes the
|
||||
/// store and the secrets and picks the identity
|
||||
/// (`voelin_ui_vm::servers::sequence`).
|
||||
pub(crate) fn transition_with<R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut AppState, &mut Cx<'_>, &Backing<'_>) -> R,
|
||||
) -> R {
|
||||
let (result, update) = self.with_parts(|state, _, host, backing| {
|
||||
let mut cx = Cx::new(host);
|
||||
let result = f(state, &mut cx, backing);
|
||||
(result, cx.update)
|
||||
});
|
||||
self.perform(update);
|
||||
result
|
||||
}
|
||||
|
||||
/// Like [`App::transition`], for a transition that changes the social
|
||||
/// state too.
|
||||
pub(crate) fn social_transition<R>(
|
||||
@@ -148,6 +179,7 @@ impl App {
|
||||
commands,
|
||||
persist,
|
||||
reloaded,
|
||||
discover,
|
||||
input_level,
|
||||
password,
|
||||
notices,
|
||||
@@ -169,6 +201,10 @@ impl App {
|
||||
for command in commands {
|
||||
self.engine.send(command);
|
||||
}
|
||||
// The gateways to look up, on the engine's runtime.
|
||||
for (id, address) in discover {
|
||||
self.look_up_gateway(id, address);
|
||||
}
|
||||
// The capture and the decoder.
|
||||
if let Some(sink) = stream.attach
|
||||
&& let Some(share) = &self.share
|
||||
|
||||
@@ -3,273 +3,116 @@
|
||||
//! the channel tree, and the callbacks' ways into the transitions of
|
||||
//! `voelin_ui_vm::servers::logic`.
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use tracing::{debug, info, warn};
|
||||
use voelin_core::{Command, JoinFailure, ObserveState};
|
||||
use voelin_core::JoinFailure;
|
||||
use voelin_core::stream::PeerConfig;
|
||||
use voelin_model::ChannelId;
|
||||
use voelin_store::{Bookmark, QueryTransport};
|
||||
use voelin_store::Bookmark;
|
||||
|
||||
use crate::app::{App, Bridge, later};
|
||||
use crate::bind::convert;
|
||||
use crate::vm;
|
||||
use crate::vm::bridge::BookmarkForm;
|
||||
use crate::vm::servers::logic::{self as logic, GatewayFound, ObservePlan};
|
||||
use crate::vm::servers::logic;
|
||||
use crate::vm::servers::sequence;
|
||||
|
||||
impl App {
|
||||
/// Connect the server on screen with voice, into its default channel
|
||||
/// ([`sequence::connect_voice`]).
|
||||
pub(crate) fn connect_voice(&mut self) {
|
||||
let channel = self
|
||||
.state
|
||||
.current
|
||||
.and_then(|id| self.bookmark(id))
|
||||
.and_then(|b| b.default_channel.clone());
|
||||
self.connect_voice_to(channel, None, None);
|
||||
let peer = self.stream_peer();
|
||||
self.transition_with(|state, cx, backing| {
|
||||
sequence::connect_voice(state, cx, backing, Some(peer))
|
||||
});
|
||||
}
|
||||
|
||||
/// Connect the current server with voice, into `channel` (a path, or
|
||||
/// `/<id>`, with its password) if given, with a privilege key if given;
|
||||
/// whether it was asked for.
|
||||
/// whether it was asked for ([`sequence::connect_voice_to`]).
|
||||
pub(crate) fn connect_voice_to(
|
||||
&mut self,
|
||||
channel: Option<String>,
|
||||
channel_password: Option<String>,
|
||||
token: Option<String>,
|
||||
) -> bool {
|
||||
let Some(b) = self.state.current.and_then(|id| self.bookmark(id)).cloned() else {
|
||||
return false;
|
||||
};
|
||||
if self.demo_ui {
|
||||
return false;
|
||||
}
|
||||
let mut options = match logic::voice_options(&b, channel, channel_password, token) {
|
||||
Ok(options) => options,
|
||||
Err(error) => {
|
||||
self.set_status(error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
options.identity = Some(voelin_core::ts::identity::to_blob(&self.identity_for(Some(b.id))));
|
||||
options.server_password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
||||
options.stream_peer = self.video.peer_config(options.stream_peer);
|
||||
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);
|
||||
true
|
||||
let peer = self.stream_peer();
|
||||
self.transition_with(|state, cx, backing| {
|
||||
sequence::connect_voice_to(
|
||||
state,
|
||||
cx,
|
||||
backing,
|
||||
channel,
|
||||
channel_password,
|
||||
token,
|
||||
Some(peer),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// The nickname a new server gets: the default identity's (one imported
|
||||
/// from TeamSpeak keeps the nickname used there), else the system user's.
|
||||
/// What this front end can decode of a stream, to connect with: the
|
||||
/// codecs of the machine, the configured one first.
|
||||
fn stream_peer(&self) -> PeerConfig {
|
||||
self.video.peer_config(PeerConfig::default())
|
||||
}
|
||||
|
||||
/// The nickname a new server gets ([`sequence::default_nickname`]).
|
||||
pub(crate) fn default_nickname(&self) -> String {
|
||||
self.store
|
||||
.default_identity()
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|identity| identity.name)
|
||||
.filter(|name| {
|
||||
![logic::CREATED_IDENTITY, voelin_core::ts::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())
|
||||
sequence::default_nickname(&self.store)
|
||||
}
|
||||
|
||||
/// Look up the gateway of a server ([`voelin_core::discover`]), once a
|
||||
/// run ([`logic::discover_wanted`]): every one the server publishes is
|
||||
/// kept, best first, and tried in turn; they take the place of a stored
|
||||
/// one that is no longer published (a gateway that moved, or one typed
|
||||
/// into an older version, which showed the field). Nothing found keeps
|
||||
/// what is stored.
|
||||
pub(crate) fn discover_gateway(&mut self, id: i64) {
|
||||
let Some(address) = self.transition(|state, cx| logic::discover_wanted(state, cx, id))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
/// Look the gateway of a server up on the engine's runtime
|
||||
/// ([`sequence::find_gateways`]), as `Update::discover` asks; what is found
|
||||
/// comes back through [`later`].
|
||||
pub(crate) fn look_up_gateway(&mut self, id: i64, address: String) {
|
||||
self.engine.runtime().spawn(async move {
|
||||
let started = Instant::now();
|
||||
let urls = voelin_core::discover::gateways(&address).await;
|
||||
let elapsed_ms = started.elapsed().as_millis() as u64;
|
||||
if urls.is_empty() {
|
||||
info!(server = %address, elapsed_ms, "no gateway published");
|
||||
} else {
|
||||
later(move |app| app.gateway_found(id, &address, urls, elapsed_ms));
|
||||
if let Some(found) = sequence::find_gateways(&address).await {
|
||||
later(move |app| app.gateway_found(id, &address, found.urls, found.elapsed_ms));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Gateways were found for the server at `address` (best first); they
|
||||
/// are kept unless the server changed meanwhile ([`logic::gateway_found`]),
|
||||
/// and the server is observed through them if it is the one shown. Users
|
||||
/// never hear of them (logged only).
|
||||
/// Gateways were found for the server at `address`
|
||||
/// ([`sequence::gateway_found`]).
|
||||
fn gateway_found(&mut self, id: i64, address: &str, urls: Vec<String>, elapsed_ms: u64) {
|
||||
let found = self.transition(|state, cx| logic::gateway_found(state, cx, id, address, urls));
|
||||
match found {
|
||||
GatewayFound::Same => {
|
||||
debug!(server = %address, elapsed_ms, "gateway found, as kept");
|
||||
}
|
||||
GatewayFound::Kept { observe } => {
|
||||
info!(server = %address, elapsed_ms, kept = true, "gateway found");
|
||||
if observe {
|
||||
self.observe(id);
|
||||
}
|
||||
}
|
||||
GatewayFound::Changed { stop, observe, urls } => {
|
||||
info!(server = %address, ?urls, elapsed_ms, kept = false, "gateway found");
|
||||
if stop {
|
||||
self.engine.send(Command::StopObserving { session: id as u64 });
|
||||
}
|
||||
if observe {
|
||||
self.observe(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.transition_with(|state, cx, backing| {
|
||||
sequence::gateway_found(state, cx, backing, id, address, urls, elapsed_ms)
|
||||
});
|
||||
}
|
||||
|
||||
/// Observe the server invisibly ([`logic::observe_plan`]): 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`).
|
||||
/// Observe the server invisibly ([`sequence::observe`]).
|
||||
pub(crate) fn observe(&mut self, id: i64) {
|
||||
let Some(b) = self.bookmark(id).cloned() else { return };
|
||||
let session = b.id as u64;
|
||||
match self.transition(|state, cx| logic::observe_plan(state, cx, id)) {
|
||||
ObservePlan::Nothing => return,
|
||||
ObservePlan::Retry(urls) => {
|
||||
debug!(server = %b.address, "still connecting to the gateway: try now");
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls,
|
||||
identity: Box::new(voelin_core::ts::identity::to_blob(
|
||||
&self.identity_for(Some(b.id)),
|
||||
)),
|
||||
});
|
||||
return;
|
||||
}
|
||||
ObservePlan::Gateway(urls) => {
|
||||
info!(server = %b.address, ?urls, "observing through the gateway");
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls,
|
||||
identity: Box::new(voelin_core::ts::identity::to_blob(
|
||||
&self.identity_for(Some(b.id)),
|
||||
)),
|
||||
});
|
||||
// Still the one the server publishes?
|
||||
self.discover_gateway(b.id);
|
||||
}
|
||||
ObservePlan::Query(q) => {
|
||||
let secret = self.secrets.get(&b.query_password_key()).ok().flatten();
|
||||
let transport = match q.transport {
|
||||
QueryTransport::Raw => voelin_core::QueryTransport::Raw,
|
||||
QueryTransport::Ssh => voelin_core::QueryTransport::Ssh,
|
||||
QueryTransport::Http => voelin_core::QueryTransport::Http,
|
||||
};
|
||||
let connect = voelin_core::QueryLogin {
|
||||
transport,
|
||||
address: format!("{}:{}", q.host, q.port),
|
||||
user: q.user.clone(),
|
||||
secret,
|
||||
server_port: q.server_port,
|
||||
server_id: None,
|
||||
allowlisted: false,
|
||||
};
|
||||
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
|
||||
}
|
||||
ObservePlan::Discover => {
|
||||
self.discover_gateway(b.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.set_status("Observing invisibly…");
|
||||
self.transition_with(|state, cx, backing| sequence::observe(state, cx, backing, id));
|
||||
}
|
||||
|
||||
/// Show a server, and observe it.
|
||||
/// Show a server, and observe it ([`sequence::select_server`]).
|
||||
pub(crate) fn select_server(&mut self, id: i64) {
|
||||
self.transition(|state, cx| logic::select_server(state, cx, id));
|
||||
self.observe(id);
|
||||
self.transition_with(|state, cx, backing| sequence::select_server(state, cx, backing, id));
|
||||
}
|
||||
|
||||
pub(crate) fn bookmark_form(&self, id: i64) -> BookmarkForm {
|
||||
let Some(b) = self.bookmark(id) else {
|
||||
return BookmarkForm {
|
||||
id: -1,
|
||||
nickname: self.default_nickname().into(),
|
||||
..Default::default()
|
||||
};
|
||||
};
|
||||
let password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
||||
let state = self.state.sessions.get(&b.id).map(|view| &view.state);
|
||||
vm::servers::form(b, state, password.as_deref().unwrap_or_default())
|
||||
sequence::bookmark_form(&self.state, &self.store, &*self.secrets, id)
|
||||
}
|
||||
|
||||
/// Save the server dialog's server, and show it; its id, none when it
|
||||
/// could not be saved (the toast says why).
|
||||
/// could not be saved (the toast says why) ([`sequence::save_bookmark`]).
|
||||
pub(crate) fn save_bookmark(&mut self, form: &BookmarkForm) -> Option<i64> {
|
||||
let old = self.bookmark(form.id as i64).cloned();
|
||||
let mut bookmark =
|
||||
logic::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 {
|
||||
self.store.update_bookmark(&bookmark)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
self.set_status(format!("Could not save: {e}"));
|
||||
return None;
|
||||
}
|
||||
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, and its
|
||||
// gateway is looked up anew.
|
||||
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.state.gateways_looked_up.remove(&bookmark.id);
|
||||
self.engine.send(Command::StopObserving { session: bookmark.id as u64 });
|
||||
if let Some(view) = self.state.sessions.get_mut(&bookmark.id) {
|
||||
view.state.observe = ObserveState::Off;
|
||||
}
|
||||
}
|
||||
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.select_server(bookmark.id);
|
||||
Some(bookmark.id)
|
||||
self.transition_with(|state, cx, backing| sequence::save_bookmark(state, cx, backing, form))
|
||||
}
|
||||
|
||||
/// 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.
|
||||
/// ([`sequence::save_and_connect`]). 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
|
||||
let peer = self.stream_peer();
|
||||
self.transition_with(|state, cx, backing| {
|
||||
sequence::save_and_connect(state, cx, backing, form, Some(peer))
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) 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);
|
||||
let bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.transition(|state, cx| logic::forget_server(state, cx, id, bookmarks));
|
||||
self.transition_with(|state, cx, backing| {
|
||||
sequence::delete_bookmark(state, cx, backing, id)
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn server_list_icon(&self, bookmark: &Bookmark) -> vm::ImageRef {
|
||||
|
||||
Reference in new issue
Block a user