From 7463cf39050dbc473f2b4eb0c78d647c32d67eeb Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Mon, 23 Nov 2026 19:47:08 +0100 Subject: [PATCH] app: stop playback when the window closes or hides Closing the window leaves the app in the tray, so a clip or a review kept playing with no picture. The window's close and the app's quit now pause the open clip and every review player, and Hide pauses them too before the window goes. Reopening shows the same screen, paused where it was. --- app/src/app.rs | 22 +++++++++++++++++++++- app/src/main.rs | 2 ++ app/src/screens/review.rs | 11 +++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/app.rs b/app/src/app.rs index 84b27cf..ec9d33c 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -388,6 +388,16 @@ impl App { } } + /// Stop the clip and the review where they are. The window is going away and the app stays + /// in the tray, so sound with no picture should not carry on: reopening shows the same + /// screen, paused at the same second. + pub fn pause_playback(&mut self) { + if let Some(player) = self.clip.as_ref().and_then(|view| view.player.as_ref()) { + player.pause(); + } + self.review.pause(); + } + pub fn refresh_settings(&self) { self.daemon.get_settings(); } @@ -620,6 +630,13 @@ thread_local! { const { std::cell::RefCell::new(None) }; } +/// Stop whatever the window was playing when it closes or the app quits. Closing the window +/// leaves the app in the tray, so a clip or a review left playing would keep making sound with +/// no picture. Reopening brings the same screen back, paused where it was. +pub fn window_closed(app: &mut App, _tx: &mut Tx) { + app.pause_playback(); +} + pub fn remember_window(handle: &rune::WindowHandle) { WINDOW.with(|slot| *slot.borrow_mut() = Some(handle.clone())); } @@ -946,7 +963,10 @@ impl App { match event { rune::TrayEvent::Activate { .. } => show_window(), rune::TrayEvent::Menu(id) if id == "show" => show_window(), - rune::TrayEvent::Menu(id) if id == "hide" => hide_window(), + rune::TrayEvent::Menu(id) if id == "hide" => { + self.pause_playback(); + hide_window(); + } rune::TrayEvent::Menu(id) if id == "record" => { if self.status.is_recording { self.daemon.stop_recording(); diff --git a/app/src/main.rs b/app/src/main.rs index 7251737..d19f58d 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -165,6 +165,8 @@ fn main() { }) .args(args) .keep_running() + .on_close(app::window_closed) + .on_quit(app::window_closed) .on_ready(move |handle| { app::remember_window(handle); if hidden { diff --git a/app/src/screens/review.rs b/app/src/screens/review.rs index 1d7d50b..11067e6 100644 --- a/app/src/screens/review.rs +++ b/app/src/screens/review.rs @@ -232,6 +232,17 @@ impl Review { } } + /// Stop the video and its soundtrack players. The window is closing under them and the app + /// stays in the tray, so sound with no picture should not carry on. + pub fn pause(&mut self) { + if let Some(player) = &self.player { + player.pause(); + } + for channel in &self.sounds { + channel.sound.pause(); + } + } + pub(crate) fn playback(&mut self) { let playing = self.player.as_ref().is_some_and(Player::is_playing); if let Some(player) = &self.player {