From d2267e55e74daef7a420c6e856cdf01895a14a31 Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 28 Oct 2026 10:33:18 +0300 Subject: [PATCH] voelin-gpui: run starts the hotkey, the state does not The previous commit started the global push-to-talk task in AppState::new when there was an engine, which a test of the state with a real engine has: it asked the desktop for a shortcut (the X11 backend on whatever DISPLAY is set, the portal on a Wayland session: a dialog on the user's desktop) and the task's status line came back to the foreground from a tokio thread, which the test scheduler reported as a test that is not deterministic (one run in six of closing_counts_the_sessions_the_engine_was_told_to_close). run() starts it once the window is open (AppState::start_global_ptt), the state never does, and the test says so. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-gpui/src/app.rs | 19 ++++++++++++++----- crates/voelin-gpui/src/lib.rs | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/voelin-gpui/src/app.rs b/crates/voelin-gpui/src/app.rs index 5d2585a..a978530 100644 --- a/crates/voelin-gpui/src/app.rs +++ b/crates/voelin-gpui/src/app.rs @@ -403,11 +403,6 @@ impl AppState { if state.switches.voice { state.transition(cx, |state, cx| logic::show_voice_view(state, cx, true)); } - state.set_global_ptt(hotkey_wanted( - &state.vm.settings, - state.switches.demo_ui, - state.engine.is_some(), - )); state } @@ -982,6 +977,16 @@ impl AppState { cx.notify(); } + /// Start the global push-to-talk hotkey as the settings say (`global_ptt`, + /// `ptt_key`) when there is an engine and no sample servers. [`crate::run`] + /// calls it once the window is open; the state does not start it by itself, + /// so that a test of the state with a real engine never asks the desktop for + /// a shortcut. + pub fn start_global_ptt(&mut self) { + let key = hotkey_wanted(&self.vm.settings, self.switches.demo_ui, self.engine.is_some()); + self.set_global_ptt(key); + } + /// Register the global push-to-talk hotkey with `key` in place of the one /// registered, or none: the task starts on the engine's runtime with the /// first key ([`crate::hotkey`]; the settings page of its slice calls this @@ -1572,6 +1577,10 @@ mod tests { switches: Switches::default(), }; let app = cx.new(|cx| AppState::new(setup, cx)); + assert!( + app.read_with(cx, |app, _| app.ptt.is_none()), + "the state starts no hotkey by itself: run does, with the window" + ); assert_eq!(app.update(cx, |app, cx| app.shutdown(cx)), 0, "no session open yet"); tx.send(voice(VoiceState::Connected)).unwrap(); cx.run_until_parked(); diff --git a/crates/voelin-gpui/src/lib.rs b/crates/voelin-gpui/src/lib.rs index de04d7b..8591575 100644 --- a/crates/voelin-gpui/src/lib.rs +++ b/crates/voelin-gpui/src/lib.rs @@ -151,6 +151,9 @@ fn open_main_window( }; move |cx| AppState::new(setup, cx) }); + // The global push-to-talk key, on the engine's runtime (docs/ui.md): once the + // state exists, and never from a test of the state. + app.update(cx, |app, _| app.start_global_ptt()); let options = { let app = app.read(cx); window_options(switches, app.remembered_window(), app.window_title(), cx)