From 4918596f711c9e7ad4844517ffc628cfd9cfed72 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Tue, 20 Aug 2024 14:07:14 +0200 Subject: [PATCH] desktop: Remove Windows workaround for picking files See https://github.com/rust-windowing/winit/issues/2291#issuecomment-2277033786 --- desktop/src/app.rs | 2 +- desktop/src/gui/widgets.rs | 2 +- desktop/src/util.rs | 32 +------------------------------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/desktop/src/app.rs b/desktop/src/app.rs index ee6e881aaa09..6c2764cbf931 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -514,7 +514,7 @@ impl App { } winit::event::Event::UserEvent(RuffleEvent::BrowseAndOpen(options)) => { - if let Some(url) = pick_file(false, None, Some(self.window.clone())) + if let Some(url) = pick_file(None, Some(&self.window)) .and_then(|p| Url::from_file_path(p).ok()) { self.gui diff --git a/desktop/src/gui/widgets.rs b/desktop/src/gui/widgets.rs index 42db70d49eb0..44cc8ffc919f 100644 --- a/desktop/src/gui/widgets.rs +++ b/desktop/src/gui/widgets.rs @@ -64,7 +64,7 @@ impl PathOrUrlField { path }); - if let Some(path) = pick_file(true, dir, self.window.upgrade()) { + 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(); } diff --git a/desktop/src/util.rs b/desktop/src/util.rs index 02a710357125..84900d240195 100644 --- a/desktop/src/util.rs +++ b/desktop/src/util.rs @@ -4,14 +4,12 @@ use gilrs::Button; use rfd::FileDialog; use ruffle_core::events::{GamepadButton, KeyCode, TextControlCode}; use std::path::{Path, PathBuf}; -use std::sync::Arc; use url::Url; use wgpu::rwh::{HasDisplayHandle, HasWindowHandle}; use winit::dpi::PhysicalSize; use winit::event::{KeyEvent, Modifiers}; use winit::event_loop::EventLoop; use winit::keyboard::{Key, KeyLocation, NamedKey}; -use winit::window::Window; /// Converts a winit event to a Ruffle `TextControlCode`. /// Returns `None` if there is no match. @@ -247,7 +245,7 @@ pub fn parse_url(path: &Path) -> Result { } } -fn actually_pick_file( +pub fn pick_file( dir: Option, parent: Option<&W>, ) -> Option { @@ -267,34 +265,6 @@ fn actually_pick_file( dialog.pick_file() } -// [NA] Horrible hacky workaround for https://github.com/rust-windowing/winit/issues/2291 -// We only need the workaround from within UI code, not when executing custom events -// The workaround causes Ruffle to show as "not responding" on windows, so we don't use it if we don't need to -#[cfg(windows)] -pub fn pick_file( - in_ui: bool, - path: Option, - parent: Option>, -) -> Option { - if in_ui { - std::thread::spawn(move || actually_pick_file(path, parent.as_ref())) - .join() - .ok() - .flatten() - } else { - actually_pick_file(path, parent.as_ref()) - } -} - -#[cfg(not(windows))] -pub fn pick_file( - _in_ui: bool, - path: Option, - parent: Option>, -) -> Option { - actually_pick_file(path, parent.as_ref()) -} - #[cfg(not(feature = "tracy"))] pub fn plot_stats_in_tracy(_instance: &wgpu::Instance) {}