The window opens the client's store as the Slint front end's run() does (backend.rs): the database in the platform's data directory (VOELIN_DATA_DIR moves it), the settings service on it with the UI's keys, the secrets (the OS keyring, memory when it refuses), the default identity (made and kept when the store has none), the chat history and the settings handed to the engine. The state starts from the store's bookmarks, the settings' theme and text size (a development switch still wins), and the sample servers of VOELIN_DEMO_UI through the app's own events with nothing sent to the engine or kept. AppState gains the callbacks of bind/servers.rs that the shell has: select a server (and observe it through its gateway or query login, the gateway looked up on the engine's runtime and handed back through Later), connect and disconnect voice, mute the microphone and the sound, hold to talk, copy an invite, and add, edit, save-and-connect and remove a bookmark, all through voelin-ui-vm's logic; perform() carries out an Update as far as this front end has the parts (commands, status, what to keep, the theme settings). It keeps the window's place in ui.window at the tick and at close, and opens the window where it was left if a screen still shows its corner. The engine-event task takes what is queued (BATCH, 64) in one update with one notification and yields to GPUI's executor between steps; the tick counts and notifies nobody, since nothing the shell shows moves with the clock. Tests: one per behaviour on GPUI's test platform (the store's servers, select, save, edit, remove, connect, the other commands, observe, the sample servers, the theme settings, the window's place, the burst and the quiet tick), and a connect through a real engine with no connector, which answers that none serves the address. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
//! The engine this front end runs on, the same one the Slint front end
|
|
//! hosts (`voelin_ui::HostedEngine`, `crates/voelin-ui/src/app.rs`): started
|
|
//! on a tokio runtime, its events forwarded into a channel the window reads.
|
|
//! The Slint crate cannot be a dependency here (it brings Slint in), so the
|
|
//! few lines are repeated; both go into `voelin-ui-vm` when the Slint front
|
|
//! end is retired.
|
|
|
|
use tokio::runtime::{Handle, Runtime};
|
|
use tokio::sync::{broadcast, mpsc};
|
|
use voelin_core::settings::Settings;
|
|
use voelin_core::{Backends, Engine, Event, History};
|
|
|
|
/// An engine owned by the caller of [`crate::run`].
|
|
pub struct HostedEngine {
|
|
/// The handle: commands go in through it.
|
|
pub engine: Engine,
|
|
/// The runtime the engine runs on; the window's helpers run there too.
|
|
pub runtime: Handle,
|
|
/// The engine's events for the window: first those that rebuild the
|
|
/// current state of every session, then new ones. Reading them needs no
|
|
/// reactor, so the window's foreground executor can await it.
|
|
pub events: mpsc::UnboundedReceiver<Event>,
|
|
}
|
|
|
|
impl HostedEngine {
|
|
/// A new engine on `runtime`, all of whose events go to the window.
|
|
pub fn start(runtime: &Runtime) -> Self {
|
|
Self::forward(runtime, runtime.block_on(async { Engine::start() }))
|
|
}
|
|
|
|
/// A new engine on `runtime` that connects with `backends` only, and keeps
|
|
/// nothing (settings and chat history in memory): the tests' (with
|
|
/// [`Backends::empty`] a connect ends at once, saying that no connector
|
|
/// serves the address, and touches neither the network nor the sound
|
|
/// devices).
|
|
pub fn start_with_backends(runtime: &Runtime, backends: Backends) -> Self {
|
|
Self::forward(
|
|
runtime,
|
|
runtime.block_on(async {
|
|
Engine::start_with_backends(Settings::in_memory(), History::in_memory(), backends)
|
|
}),
|
|
)
|
|
}
|
|
|
|
/// Forward the events of `engine` into the channel the window reads.
|
|
fn forward(runtime: &Runtime, engine: Engine) -> Self {
|
|
let (tx, events) = mpsc::unbounded_channel();
|
|
let mut rx = engine.subscribe();
|
|
runtime.spawn(async move {
|
|
loop {
|
|
match rx.recv().await {
|
|
Ok(event) => {
|
|
if tx.send(event).is_err() {
|
|
break;
|
|
}
|
|
}
|
|
Err(broadcast::error::RecvError::Lagged(_)) => continue,
|
|
Err(_) => break,
|
|
}
|
|
}
|
|
});
|
|
Self { engine, runtime: runtime.handle().clone(), events }
|
|
}
|
|
}
|