fix(core): dialog freezing regression on macOS (#1768)

This commit is contained in:
Lucas Fernandes Nogueira 2021-05-10 15:02:50 -03:00 committed by GitHub
parent 72b8048b5a
commit d06e1de46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -104,6 +104,13 @@ impl Module {
.and_then(|r| r.json)
.map_err(InvokeError::from)
}),
// on macOS, the dialog must run on another thread: https://github.com/rust-windowing/winit/issues/1779
// we do the same on Windows just to stay consistent with `tao` (and it also improves UX because of the event loop)
#[cfg(not(target_os = "linux"))]
Self::Dialog(cmd) => resolver
.respond_async(async move { cmd.run().and_then(|r| r.json).map_err(InvokeError::from) }),
// on Linux, the dialog must run on the main thread.
#[cfg(target_os = "linux")]
Self::Dialog(cmd) => {
let _ = window.run_on_main_thread(|| {
resolver

View File

@ -50,7 +50,7 @@ use crate::{
runtime::window::PendingWindow,
};
use serde::Serialize;
use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc};
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
// Export types likely to be used by the application.
#[cfg(any(feature = "menu", feature = "system-tray"))]
@ -137,7 +137,7 @@ pub struct Context<A: Assets> {
/// The icon to use use on the system tray UI.
#[cfg(target_os = "linux")]
pub system_tray_icon: Option<PathBuf>,
pub system_tray_icon: Option<std::path::PathBuf>,
/// The icon to use use on the system tray UI.
#[cfg(not(target_os = "linux"))]

View File

@ -180,6 +180,7 @@ impl<P: Params> Window<P> {
self.window.dispatcher.clone()
}
#[allow(dead_code)]
pub(crate) fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> crate::Result<()> {
self
.window