Skip to content

Commit

Permalink
desktop: Close dialogs when the player is destroyed
Browse files Browse the repository at this point in the history
This patch closes all dialogs upon destroying a player
(e.g. by closing the file or opening a new one).
Only dialogs that have a notifier are closed.
  • Loading branch information
kjarosh committed Oct 11, 2024
1 parent 5eec59e commit 6a6d660
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl ApplicationHandler<RuffleEvent> 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 => {
Expand Down
6 changes: 6 additions & 0 deletions desktop/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
}
Expand Down
6 changes: 6 additions & 0 deletions desktop/src/gui/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions desktop/src/gui/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6a6d660

Please sign in to comment.