Skip to content

Commit

Permalink
desktop: Remove Windows workaround for picking files
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh authored and torokati44 committed Aug 20, 2024
1 parent 8755dd9 commit 4918596
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 33 deletions.
2 changes: 1 addition & 1 deletion desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/gui/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
32 changes: 1 addition & 31 deletions desktop/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -247,7 +245,7 @@ pub fn parse_url(path: &Path) -> Result<Url, Error> {
}
}

fn actually_pick_file<W: HasWindowHandle + HasDisplayHandle>(
pub fn pick_file<W: HasWindowHandle + HasDisplayHandle>(
dir: Option<PathBuf>,
parent: Option<&W>,
) -> Option<PathBuf> {
Expand All @@ -267,34 +265,6 @@ fn actually_pick_file<W: HasWindowHandle + HasDisplayHandle>(
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<PathBuf>,
parent: Option<Arc<Window>>,
) -> Option<PathBuf> {
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<PathBuf>,
parent: Option<Arc<Window>>,
) -> Option<PathBuf> {
actually_pick_file(path, parent.as_ref())
}

#[cfg(not(feature = "tracy"))]
pub fn plot_stats_in_tracy(_instance: &wgpu::Instance) {}

Expand Down

0 comments on commit 4918596

Please sign in to comment.