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 {