Skip to content

Commit fe32afc

Browse files
authored
fix(core): Window must be Send + Sync on Windows, closes #2078 (#2093)
1 parent 8c13344 commit fe32afc

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

.changes/window-send-sync.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime-wry": patch
4+
"tauri-runtime": patch
5+
---
6+
7+
`Window` is now `Send + Sync` on Windows.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl From<FileDropEventWrapper> for FileDropEvent {
594594
}
595595

596596
#[cfg(windows)]
597-
struct Hwnd(*mut std::ffi::c_void);
597+
struct Hwnd(HWND);
598598
#[cfg(windows)]
599599
unsafe impl Send for Hwnd {}
600600

@@ -823,7 +823,7 @@ impl Dispatch for WryDispatcher {
823823
}
824824

825825
#[cfg(windows)]
826-
fn hwnd(&self) -> Result<*mut std::ffi::c_void> {
826+
fn hwnd(&self) -> Result<HWND> {
827827
Ok(dispatcher_getter!(self, WindowMessage::Hwnd).0)
828828
}
829829

@@ -1594,7 +1594,7 @@ fn handle_event_loop(
15941594
#[cfg(windows)]
15951595
WindowMessage::Hwnd(tx) => {
15961596
use wry::application::platform::windows::WindowExtWindows;
1597-
tx.send(Hwnd(window.hwnd())).unwrap()
1597+
tx.send(Hwnd(window.hwnd() as HWND)).unwrap()
15981598
}
15991599
// Setters
16001600
WindowMessage::Center(tx) => {

core/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::{fmt::Debug, hash::Hash, path::PathBuf};
1111
use serde::{Deserialize, Serialize};
1212
use tauri_utils::assets::Assets;
1313
use uuid::Uuid;
14+
#[cfg(windows)]
15+
use winapi::shared::windef::HWND;
1416

1517
/// Create window and system tray menus.
1618
#[cfg(any(feature = "menu", feature = "system-tray"))]
@@ -413,7 +415,7 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
413415

414416
/// Returns the native handle that is used by this window.
415417
#[cfg(windows)]
416-
fn hwnd(&self) -> crate::Result<*mut std::ffi::c_void>;
418+
fn hwnd(&self) -> crate::Result<HWND>;
417419

418420
// SETTERS
419421

core/tauri/src/window.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,12 @@ impl<P: Params> Window<P> {
503503
/// You can spawn a task to use the API using the [`async_runtime`](crate::async_runtime) to prevent the panic.
504504
#[cfg(windows)]
505505
pub fn hwnd(&self) -> crate::Result<*mut std::ffi::c_void> {
506-
self.window.dispatcher.hwnd().map_err(Into::into)
506+
self
507+
.window
508+
.dispatcher
509+
.hwnd()
510+
.map(|hwnd| hwnd as *mut _)
511+
.map_err(Into::into)
507512
}
508513

509514
// Setters

0 commit comments

Comments
 (0)