Jelajahi Sumber

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

Lucas Fernandes Nogueira 4 tahun lalu
induk
melakukan
d06e1de46b
3 mengubah file dengan 10 tambahan dan 2 penghapusan
  1. 7 0
      core/tauri/src/endpoints.rs
  2. 2 2
      core/tauri/src/lib.rs
  3. 1 0
      core/tauri/src/window.rs

+ 7 - 0
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

+ 2 - 2
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<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"))]

+ 1 - 0
core/tauri/src/window.rs

@@ -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