Jelajahi Sumber

fix(core): deadlock on plugin webview ready hook (#4462)

Lucas Fernandes Nogueira 3 tahun lalu
induk
melakukan
9d33d09341
2 mengubah file dengan 12 tambahan dan 5 penghapusan
  1. 5 0
      .changes/fix-plugin-deadlock.md
  2. 7 5
      core/tauri/src/manager.rs

+ 5 - 0
.changes/fix-plugin-deadlock.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fixes deadlock when a plugin window ready event needs to block the thread waiting on the event loop.

+ 7 - 5
core/tauri/src/manager.rs

@@ -1192,14 +1192,16 @@ impl<R: Runtime> WindowManager<R> {
     }
 
     // let plugins know that a new window has been added to the manager
-    {
-      self
-        .inner
+    let manager = self.inner.clone();
+    let window_ = window.clone();
+    // run on main thread so the plugin store doesn't dead lock with the event loop handler in App
+    let _ = window.run_on_main_thread(move || {
+      manager
         .plugins
         .lock()
         .expect("poisoned plugin store")
-        .created(window.clone());
-    }
+        .created(window_);
+    });
 
     window
   }