diff --git a/desktop/src/app.rs b/desktop/src/app.rs index 6c2764cbf931..f8ff057de5e1 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -136,6 +136,7 @@ impl App { // Poll UI events. let event_loop = self.event_loop.take().expect("App already running"); + let event_loop_proxy = event_loop.create_proxy(); event_loop.run(move |event, elwt| { let mut check_redraw = false; match event { @@ -514,13 +515,16 @@ impl App { } winit::event::Event::UserEvent(RuffleEvent::BrowseAndOpen(options)) => { - if let Some(url) = pick_file(None, Some(&self.window)) - .and_then(|p| Url::from_file_path(p).ok()) - { - self.gui - .borrow_mut() - .create_movie(&mut self.player, *options, url); - } + let event_loop = event_loop_proxy.clone(); + let window = self.window.clone(); + tokio::spawn(async move { + if let Some(url) = pick_file(None, Some(&window)) + .await + .and_then(|p| Url::from_file_path(p).ok()) + { + let _ = event_loop.send_event(RuffleEvent::OpenURL(url, options)); + } + }); } winit::event::Event::UserEvent(RuffleEvent::OpenURL(url, options)) => { diff --git a/desktop/src/gui/widgets.rs b/desktop/src/gui/widgets.rs index 44cc8ffc919f..ca05e4acd0bc 100644 --- a/desktop/src/gui/widgets.rs +++ b/desktop/src/gui/widgets.rs @@ -64,10 +64,14 @@ impl PathOrUrlField { path }); - if let Some(path) = pick_file(dir, self.window.upgrade().as_ref()) { - let mut value_lock = Self::lock_value(&self.value); - *value_lock = path.to_string_lossy().to_string(); - } + let value = self.value.clone(); + let window = self.window.upgrade(); + tokio::spawn(async move { + if let Some(path) = pick_file(dir, window.as_ref()).await { + let mut value_lock = Self::lock_value(&value); + *value_lock = path.to_string_lossy().to_string(); + } + }); } let mut value_locked = Self::lock_value(&self.value); diff --git a/desktop/src/util.rs b/desktop/src/util.rs index 84900d240195..d60404061d00 100644 --- a/desktop/src/util.rs +++ b/desktop/src/util.rs @@ -1,7 +1,7 @@ use crate::custom_event::RuffleEvent; use anyhow::{anyhow, Error}; use gilrs::Button; -use rfd::FileDialog; +use rfd::AsyncFileDialog; use ruffle_core::events::{GamepadButton, KeyCode, TextControlCode}; use std::path::{Path, PathBuf}; use url::Url; @@ -245,11 +245,11 @@ pub fn parse_url(path: &Path) -> Result { } } -pub fn pick_file( +pub async fn pick_file( dir: Option, parent: Option<&W>, ) -> Option { - let mut dialog = FileDialog::new() + let mut dialog = AsyncFileDialog::new() .add_filter("Flash Files", &["swf", "spl", "ruf"]) .add_filter("All Files", &["*"]) .set_title("Load a Flash File"); @@ -262,7 +262,7 @@ pub fn pick_file( dialog = dialog.set_parent(parent); } - dialog.pick_file() + dialog.pick_file().await.map(|h| h.into()) } #[cfg(not(feature = "tracy"))]