Skip to content

Commit bb00d5b

Browse files
authored
Replace winapi with windows crate and use webview2-com instead of webview2 (#2615)
* Switch to webview2-com version of tao and wry * Pick up latest branch of TAO and WRY * Let WRY pick the branch for TAO instead of patch * Add comment for wry next branch pending merge * Add changelog * Revert wry redirect in Cargo.toml * Use pinned rev for matching PR merge commit
1 parent 205b0dc commit bb00d5b

8 files changed

Lines changed: 134 additions & 90 deletions

File tree

.changes/webview2-com.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": patch
4+
"tauri-runtime-wry": patch
5+
---
6+
7+
Replace all of the `winapi` crate references with the `windows` crate, and replace `webview2` and `webview2-sys` with `webview2-com` and `webview2-com-sys` built with the `windows` crate. This goes along with updates to the TAO and WRY `next` branches.

core/tauri-runtime-wry/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ readme = "README.md"
1313

1414
[dependencies]
1515
#wry = { version = "0.12", default-features = false, features = [ "file-drop", "protocol" ] }
16-
wry = { git = "https://github.com/tauri-apps/wry", rev = "21692d986138570d2edc31f84bddb442a3c84a9c", default-features = false, features = [ "file-drop", "protocol" ] }
16+
wry = { git = "https://github.com/tauri-apps/wry", rev = "e056fb2a15e29de1b8ed85a548cfeb1f85031357", default-features = false, features = [ "file-drop", "protocol" ] }
1717
tauri-runtime = { version = "0.2.1", path = "../tauri-runtime" }
1818
tauri-utils = { version = "1.0.0-beta.3", path = "../tauri-utils" }
1919
uuid = { version = "0.8.2", features = [ "v4" ] }
2020
infer = "0.4"
2121

2222
[target."cfg(windows)".dependencies]
2323
ico = "0.1"
24-
winapi = "0.3"
24+
webview2-com = "0.4.0"
2525

2626
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
2727
png = "0.16"

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use tauri_runtime::window::MenuEvent;
2626
#[cfg(feature = "system-tray")]
2727
use tauri_runtime::{SystemTray, SystemTrayEvent};
2828
#[cfg(windows)]
29-
use winapi::shared::windef::HWND;
29+
use webview2_com::{
30+
FocusChangedEventHandler,
31+
Windows::Win32::{Foundation::HWND, System::WinRT::EventRegistrationToken},
32+
};
3033
#[cfg(all(feature = "system-tray", target_os = "macos"))]
3134
use wry::application::platform::macos::{SystemTrayBuilderExtMacOS, SystemTrayExtMacOS};
3235
#[cfg(target_os = "linux")]
@@ -1634,25 +1637,34 @@ impl Runtime for Wry {
16341637
if let WindowHandle::Webview(ref webview) = webview.inner {
16351638
if let Some(controller) = webview.controller() {
16361639
let proxy = self.event_loop.create_proxy();
1637-
controller
1638-
.add_got_focus(move |_| {
1639-
let _ = proxy.send_event(Message::Webview(
1640-
id,
1641-
WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)),
1642-
));
1643-
Ok(())
1644-
})
1645-
.unwrap();
1640+
let mut token = EventRegistrationToken::default();
1641+
unsafe {
1642+
controller.add_GotFocus(
1643+
FocusChangedEventHandler::create(Box::new(move |_, _| {
1644+
let _ = proxy.send_event(Message::Webview(
1645+
id,
1646+
WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)),
1647+
));
1648+
Ok(())
1649+
})),
1650+
&mut token,
1651+
)
1652+
}
1653+
.unwrap();
16461654
let proxy = self.event_loop.create_proxy();
1647-
controller
1648-
.add_lost_focus(move |_| {
1649-
let _ = proxy.send_event(Message::Webview(
1650-
id,
1651-
WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)),
1652-
));
1653-
Ok(())
1654-
})
1655-
.unwrap();
1655+
unsafe {
1656+
controller.add_LostFocus(
1657+
FocusChangedEventHandler::create(Box::new(move |_, _| {
1658+
let _ = proxy.send_event(Message::Webview(
1659+
id,
1660+
WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)),
1661+
));
1662+
Ok(())
1663+
})),
1664+
&mut token,
1665+
)
1666+
}
1667+
.unwrap();
16561668
}
16571669
}
16581670
}
@@ -2024,7 +2036,7 @@ fn handle_event_loop(
20242036
#[cfg(target_os = "macos")]
20252037
WindowMessage::NSWindow(tx) => tx.send(NSWindow(window.ns_window())).unwrap(),
20262038
#[cfg(windows)]
2027-
WindowMessage::Hwnd(tx) => tx.send(Hwnd(window.hwnd() as HWND)).unwrap(),
2039+
WindowMessage::Hwnd(tx) => tx.send(Hwnd(HWND(window.hwnd() as _))).unwrap(),
20282040
#[cfg(any(
20292041
target_os = "linux",
20302042
target_os = "dragonfly",

core/tauri-runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ http-range = "0.1.4"
3232
infer = "0.4"
3333

3434
[target."cfg(windows)".dependencies]
35-
winapi = "0.3"
35+
webview2-com-sys = "0.4.0"
3636

3737
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
3838
gtk = { version = "0.14", features = [ "v3_20" ] }

core/tauri-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{fmt::Debug, path::PathBuf, sync::mpsc::Sender};
1111
use uuid::Uuid;
1212

1313
#[cfg(windows)]
14-
use winapi::shared::windef::HWND;
14+
use webview2_com_sys::Windows::Win32::Foundation::HWND;
1515

1616
pub mod http;
1717
/// Create window and system tray menus.

core/tauri-runtime/src/webview.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde_json::Value as JsonValue;
1313
use tauri_utils::config::{WindowConfig, WindowUrl};
1414

1515
#[cfg(windows)]
16-
use winapi::shared::windef::HWND;
16+
use webview2_com_sys::Windows::Win32::Foundation::HWND;
1717

1818
use std::{fmt, path::PathBuf};
1919

core/tauri/src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<R: Runtime> Window<R> {
526526
.window
527527
.dispatcher
528528
.hwnd()
529-
.map(|hwnd| hwnd as *mut _)
529+
.map(|hwnd| hwnd.0 as *mut _)
530530
.map_err(Into::into)
531531
}
532532

examples/api/src-tauri/Cargo.lock

Lines changed: 89 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)