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.
This commit is contained in:
vhaudiquet committed 2026-11-23 19:47:08 +01:00
1 parent 531238039d
commit 7463cf3905
3 files changed
+34 -1

No files matched your search

+21 -1
View File
@@ -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) { pub fn refresh_settings(&self) {
self.daemon.get_settings(); self.daemon.get_settings();
} }
@@ -620,6 +630,13 @@ thread_local! {
const { std::cell::RefCell::new(None) }; 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) { pub fn remember_window(handle: &rune::WindowHandle) {
WINDOW.with(|slot| *slot.borrow_mut() = Some(handle.clone())); WINDOW.with(|slot| *slot.borrow_mut() = Some(handle.clone()));
} }
@@ -946,7 +963,10 @@ impl App {
match event { match event {
rune::TrayEvent::Activate { .. } => show_window(), rune::TrayEvent::Activate { .. } => show_window(),
rune::TrayEvent::Menu(id) if id == "show" => 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" => { rune::TrayEvent::Menu(id) if id == "record" => {
if self.status.is_recording { if self.status.is_recording {
self.daemon.stop_recording(); self.daemon.stop_recording();
+2
View File
@@ -165,6 +165,8 @@ fn main() {
}) })
.args(args) .args(args)
.keep_running() .keep_running()
.on_close(app::window_closed)
.on_quit(app::window_closed)
.on_ready(move |handle| { .on_ready(move |handle| {
app::remember_window(handle); app::remember_window(handle);
if hidden { if hidden {
+11
View File
@@ -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) { pub(crate) fn playback(&mut self) {
let playing = self.player.as_ref().is_some_and(Player::is_playing); let playing = self.player.as_ref().is_some_and(Player::is_playing);
if let Some(player) = &self.player { if let Some(player) = &self.player {