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:
1 parent
531238039d
commit
7463cf3905
3 files changed
+34
-1
No files matched your search
+21
-1
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user