From fe32afcc933920d6282ae1d63b041b182278a031 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 27 Jun 2021 11:02:17 -0300 Subject: [PATCH] fix(core): `Window` must be `Send + Sync` on Windows, closes #2078 (#2093) --- .changes/window-send-sync.md | 7 +++++++ core/tauri-runtime-wry/src/lib.rs | 6 +++--- core/tauri-runtime/src/lib.rs | 4 +++- core/tauri/src/window.rs | 7 ++++++- 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .changes/window-send-sync.md diff --git a/.changes/window-send-sync.md b/.changes/window-send-sync.md new file mode 100644 index 000000000..bc547f2df --- /dev/null +++ b/.changes/window-send-sync.md @@ -0,0 +1,7 @@ +--- +"tauri": patch +"tauri-runtime-wry": patch +"tauri-runtime": patch +--- + +`Window` is now `Send + Sync` on Windows. diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 85b915fa6..66843ea6a 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -594,7 +594,7 @@ impl From for FileDropEvent { } #[cfg(windows)] -struct Hwnd(*mut std::ffi::c_void); +struct Hwnd(HWND); #[cfg(windows)] unsafe impl Send for Hwnd {} @@ -823,7 +823,7 @@ impl Dispatch for WryDispatcher { } #[cfg(windows)] - fn hwnd(&self) -> Result<*mut std::ffi::c_void> { + fn hwnd(&self) -> Result { Ok(dispatcher_getter!(self, WindowMessage::Hwnd).0) } @@ -1594,7 +1594,7 @@ fn handle_event_loop( #[cfg(windows)] WindowMessage::Hwnd(tx) => { use wry::application::platform::windows::WindowExtWindows; - tx.send(Hwnd(window.hwnd())).unwrap() + tx.send(Hwnd(window.hwnd() as HWND)).unwrap() } // Setters WindowMessage::Center(tx) => { diff --git a/core/tauri-runtime/src/lib.rs b/core/tauri-runtime/src/lib.rs index d8129ab09..bbed5075a 100644 --- a/core/tauri-runtime/src/lib.rs +++ b/core/tauri-runtime/src/lib.rs @@ -11,6 +11,8 @@ use std::{fmt::Debug, hash::Hash, path::PathBuf}; use serde::{Deserialize, Serialize}; use tauri_utils::assets::Assets; use uuid::Uuid; +#[cfg(windows)] +use winapi::shared::windef::HWND; /// Create window and system tray menus. #[cfg(any(feature = "menu", feature = "system-tray"))] @@ -413,7 +415,7 @@ pub trait Dispatch: Clone + Send + Sized + 'static { /// Returns the native handle that is used by this window. #[cfg(windows)] - fn hwnd(&self) -> crate::Result<*mut std::ffi::c_void>; + fn hwnd(&self) -> crate::Result; // SETTERS diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 5143eb545..c7eecd990 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -503,7 +503,12 @@ impl Window

{ /// You can spawn a task to use the API using the [`async_runtime`](crate::async_runtime) to prevent the panic. #[cfg(windows)] pub fn hwnd(&self) -> crate::Result<*mut std::ffi::c_void> { - self.window.dispatcher.hwnd().map_err(Into::into) + self + .window + .dispatcher + .hwnd() + .map(|hwnd| hwnd as *mut _) + .map_err(Into::into) } // Setters