crates/voelin-gpui/src/app.rs holds the root entity: the toolkit-free voelin_ui_vm state (`AppState<Vec<ChatLine>>`) and `Social`, with `events::handle` as the one dispatch of an engine event (the entry point both front ends use; its Update's engine commands are sent, its warnings logged, the rest belongs to the slices that draw it). Three loops, spawned by `AppState::new` and ended when the entity is released: - the engine's events: a foreground task awaits the tokio receiver of the hosted engine (no reactor needed, as the plan says), `this.update` and `cx.notify()`: spike 3's hotkey task; - the tick: a loop of `background_executor().timer(1 s)`; - `Later`, for other threads: GPUI's `AsyncApp` holds an Rc-based weak handle and is not Send (read in gpui-pre's async_context.rs), so a thread that wants to touch the entity holds a Send handle that queues a boxed closure; a third foreground task, which owns the cloned AsyncApp, runs it with the entity. This is the Slint front end's `later(|app| ...)`. engine.rs repeats the ~25 lines of voelin-ui's `HostedEngine::start` (the engine on a tokio runtime, its events forwarded into an unbounded channel): that type lives in the Slint crate (crates/voelin-ui/src/app.rs), which this crate cannot depend on and this task does not touch. dev.rs reads VOELIN_WINDOW_SIZE. lib.rs `run()` logs through tracing (`VOELIN_LOG`, else `RUST_LOG`, else a filter that shows GPUI's adapter line), starts the engine's runtime, opens the window on the entity and, on close, tells the engine to close the sessions and ends the app. view.rs shows the one line of state the task asked for: version, voice connections up, engine events handled, seconds up; each part moves by one of the loops. Seven tests, none needing a display (GPUI's test platform): an injected engine event (a voice state) reaches the entity and its status line, the entity notifies its observers, the tick runs once per advanced second, a job from another thread runs on the entity, and a real engine (HostedEngine on a tokio runtime) delivers a real event (a setting changed by a command) to the entity through the same task; the window-size switch parses and refuses nonsense. The real-engine test calls `allow_parking`, as GPUI's test scheduler calls a wake from a tokio thread a non-deterministic test otherwise. The tests use `gpui-pre` (renamed `gpui`) with its `test-support` as a dev-dependency, pinned `=0.3.10` beside gpui-kit's own pin: gpui-kit's `test-support` feature names the optional `gpui-fast` backend in weak features, which makes cargo lock gpui-fast and its tree and pins taffy to 0.15.0 for every build (reproduced in a scratch project: 793 packages without the feature, 820 with it). The lock gains only gpui-pre's own test-support crates (proptest and its few, futures-concurrency, postage); THIRD_PARTY_NOTICES.md does not move (dev-dependencies are out of it) and cargo deny passes. Run on Xvfb :97 (headless.sh) with the debug binary: the window opens in 0.1 s, shows "Voelin 0.0.1-alpha · 0 connections · 1 engine event · 2 s up" and, four seconds later, "... · 6 s up" (the one engine event is the real engine's own at start); Alt+F4 ends the app with exit code 0 in 132 ms. Checked on Rust 1.95.0: fmt and clippy -D warnings (all targets, --no-deps), `cargo test -p voelin-gpui` (3 runs, 7 tests each), cargo deny. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
//! The development switches of the GPUI front end, read from the
|
|
//! environment. They are the Slint front end's (docs/ui.md, "Development
|
|
//! switches and screenshots") where the GPUI one has the same thing to
|
|
//! switch, so that one recipe serves both.
|
|
//!
|
|
//! - `VOELIN_WINDOW_SIZE=1440x960`: the window's size.
|
|
|
|
/// What the environment switched.
|
|
#[derive(Clone, Debug, Default, PartialEq)]
|
|
pub struct Switches {
|
|
/// The window's size in pixels, when the switch names one.
|
|
pub window: Option<(f32, f32)>,
|
|
}
|
|
|
|
impl Switches {
|
|
/// The switches of this process's environment.
|
|
pub fn from_env() -> Self {
|
|
Self::parse(|name| std::env::var(name).ok())
|
|
}
|
|
|
|
/// The switches `get` answers for; what it does not understand is logged
|
|
/// and left out.
|
|
pub fn parse(get: impl Fn(&str) -> Option<String>) -> Self {
|
|
let mut switches = Self::default();
|
|
if let Some(text) = get("VOELIN_WINDOW_SIZE") {
|
|
match parse_size(&text) {
|
|
Some(size) => switches.window = Some(size),
|
|
None => tracing::warn!("VOELIN_WINDOW_SIZE={text}: WIDTHxHEIGHT, such as 1440x960"),
|
|
}
|
|
}
|
|
switches
|
|
}
|
|
}
|
|
|
|
/// `WIDTHxHEIGHT` in pixels, at least 320 by 240 and at most 16384 each way.
|
|
fn parse_size(text: &str) -> Option<(f32, f32)> {
|
|
let (w, h) = text.trim().split_once('x')?;
|
|
let (w, h): (u32, u32) = (w.parse().ok()?, h.parse().ok()?);
|
|
((320..=16384).contains(&w) && (240..=16384).contains(&h)).then_some((w as f32, h as f32))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn size_of(text: &str) -> Switches {
|
|
let text = text.to_owned();
|
|
Switches::parse(|name| (name == "VOELIN_WINDOW_SIZE").then(|| text.clone()))
|
|
}
|
|
|
|
#[test]
|
|
fn the_window_size_is_read() {
|
|
assert_eq!(size_of("1440x960").window, Some((1440.0, 960.0)));
|
|
assert_eq!(Switches::parse(|_| None), Switches::default());
|
|
}
|
|
|
|
#[test]
|
|
fn what_makes_no_sense_is_left_out() {
|
|
for text in ["10x10", "1440", "axb", "99999x99999", ""] {
|
|
assert_eq!(size_of(text), Switches::default(), "{text:?}");
|
|
}
|
|
}
|
|
}
|