fix(core): Window must be Send + Sync on Windows, closes #2078 (#2093)

This commit is contained in:
Lucas Fernandes Nogueira
2021-06-27 11:02:17 -03:00
committed by GitHub
parent 8c13344f8f
commit fe32afcc93
4 changed files with 19 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime-wry": patch
"tauri-runtime": patch
---
`Window` is now `Send + Sync` on Windows.

View File

@@ -594,7 +594,7 @@ impl From<FileDropEventWrapper> 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<HWND> {
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) => {

View File

@@ -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<HWND>;
// SETTERS

View File

@@ -503,7 +503,12 @@ impl<P: Params> Window<P> {
/// 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