Skip to content

Commit

Permalink
fix(core): Window must be Send + Sync on Windows, closes #2078 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jun 27, 2021
1 parent 8c13344 commit fe32afc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/window-send-sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime-wry": patch
"tauri-runtime": patch
---

`Window` is now `Send + Sync` on Windows.
6 changes: 3 additions & 3 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe32afc

Please sign in to comment.