diff --git a/desktop/src/app.rs b/desktop/src/app.rs index b63e028cd17b..dbd073a48b41 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -289,7 +289,7 @@ impl ApplicationHandler for App { RuffleEvent::CloseFile => { self.window.set_title("Ruffle"); // Reset title since file has been closed. - self.player.destroy(); + self.gui.borrow_mut().close_movie(&mut self.player); } RuffleEvent::EnterFullScreen => { diff --git a/desktop/src/gui.rs b/desktop/src/gui.rs index 7d7a1892c8ce..9bc718edf063 100644 --- a/desktop/src/gui.rs +++ b/desktop/src/gui.rs @@ -213,6 +213,11 @@ impl RuffleGui { self.context_menu.is_some() } + /// Notifies the GUI that the player has been destroyed. + fn on_player_destroyed(&mut self) { + self.dialogs.close_dialogs_with_notifiers(); + } + /// Notifies the GUI that a new player was created. fn on_player_created( &mut self, @@ -225,6 +230,7 @@ impl RuffleGui { // Update dialog state to reflect the newly-opened movie's options. self.dialogs .recreate_open_dialog(opt, Some(movie_url), self.event_loop.clone()); + self.dialogs.close_dialogs_with_notifiers(); player.set_volume(self.dialogs.volume_controls.get_volume()); } diff --git a/desktop/src/gui/controller.rs b/desktop/src/gui/controller.rs index c0162c74b610..5ba9511666a2 100644 --- a/desktop/src/gui/controller.rs +++ b/desktop/src/gui/controller.rs @@ -221,12 +221,18 @@ impl GuiController { response.consumed } + pub fn close_movie(&mut self, player: &mut PlayerController) { + player.destroy(); + self.gui.on_player_destroyed(); + } + pub fn create_movie( &mut self, player: &mut PlayerController, opt: LaunchOptions, movie_url: Url, ) { + self.close_movie(player); let movie_view = MovieView::new( self.movie_view_renderer.clone(), &self.descriptors.device, diff --git a/desktop/src/gui/dialogs.rs b/desktop/src/gui/dialogs.rs index a240e35a3753..929d621210f0 100644 --- a/desktop/src/gui/dialogs.rs +++ b/desktop/src/gui/dialogs.rs @@ -106,6 +106,16 @@ impl Dialogs { self.picker.clone() } + /// Close all dialogs that have someone waiting for an answer. + /// + /// This method may be used when the original receiver is closed, + /// e.g. by loading a new movie or destroying the existing one. + pub fn close_dialogs_with_notifiers(&mut self) { + self.network_access_dialog_queue.clear(); + self.filesystem_access_dialog = None; + self.filesystem_access_dialog_queue.clear(); + } + pub fn recreate_open_dialog( &mut self, opt: LaunchOptions,