From d06e1de46bb5482624f451447e8195de6d905b4b Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 10 May 2021 15:02:50 -0300 Subject: [PATCH] fix(core): dialog freezing regression on macOS (#1768) --- core/tauri/src/endpoints.rs | 7 +++++++ core/tauri/src/lib.rs | 4 ++-- core/tauri/src/window.rs | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/tauri/src/endpoints.rs b/core/tauri/src/endpoints.rs index a24f90ce5..0f7ccafb5 100644 --- a/core/tauri/src/endpoints.rs +++ b/core/tauri/src/endpoints.rs @@ -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 diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index 01f872af1..be8b0f85c 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -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 { /// The icon to use use on the system tray UI. #[cfg(target_os = "linux")] - pub system_tray_icon: Option, + pub system_tray_icon: Option, /// The icon to use use on the system tray UI. #[cfg(not(target_os = "linux"))] diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index f53d43909..3c516c773 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -180,6 +180,7 @@ impl Window

{ self.window.dispatcher.clone() } + #[allow(dead_code)] pub(crate) fn run_on_main_thread(&self, f: F) -> crate::Result<()> { self .window