diff --git a/.changes/webview2-com.md b/.changes/webview2-com.md new file mode 100644 index 000000000..bddac4929 --- /dev/null +++ b/.changes/webview2-com.md @@ -0,0 +1,7 @@ +--- +"tauri": patch +"tauri-runtime": patch +"tauri-runtime-wry": patch +--- + +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. \ No newline at end of file diff --git a/core/tauri-runtime-wry/Cargo.toml b/core/tauri-runtime-wry/Cargo.toml index af99ea8db..0d1ea0244 100644 --- a/core/tauri-runtime-wry/Cargo.toml +++ b/core/tauri-runtime-wry/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" [dependencies] #wry = { version = "0.12", default-features = false, features = [ "file-drop", "protocol" ] } -wry = { git = "https://github.com/tauri-apps/wry", rev = "21692d986138570d2edc31f84bddb442a3c84a9c", default-features = false, features = [ "file-drop", "protocol" ] } +wry = { git = "https://github.com/tauri-apps/wry", rev = "e056fb2a15e29de1b8ed85a548cfeb1f85031357", default-features = false, features = [ "file-drop", "protocol" ] } tauri-runtime = { version = "0.2.1", path = "../tauri-runtime" } tauri-utils = { version = "1.0.0-beta.3", path = "../tauri-utils" } uuid = { version = "0.8.2", features = [ "v4" ] } @@ -21,7 +21,7 @@ infer = "0.4" [target."cfg(windows)".dependencies] ico = "0.1" -winapi = "0.3" +webview2-com = "0.4.0" [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] png = "0.16" diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 8a2c70835..e42f9c252 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -26,7 +26,10 @@ use tauri_runtime::window::MenuEvent; #[cfg(feature = "system-tray")] use tauri_runtime::{SystemTray, SystemTrayEvent}; #[cfg(windows)] -use winapi::shared::windef::HWND; +use webview2_com::{ + FocusChangedEventHandler, + Windows::Win32::{Foundation::HWND, System::WinRT::EventRegistrationToken}, +}; #[cfg(all(feature = "system-tray", target_os = "macos"))] use wry::application::platform::macos::{SystemTrayBuilderExtMacOS, SystemTrayExtMacOS}; #[cfg(target_os = "linux")] @@ -1634,25 +1637,34 @@ impl Runtime for Wry { if let WindowHandle::Webview(ref webview) = webview.inner { if let Some(controller) = webview.controller() { let proxy = self.event_loop.create_proxy(); - controller - .add_got_focus(move |_| { - let _ = proxy.send_event(Message::Webview( - id, - WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)), - )); - Ok(()) - }) - .unwrap(); + let mut token = EventRegistrationToken::default(); + unsafe { + controller.add_GotFocus( + FocusChangedEventHandler::create(Box::new(move |_, _| { + let _ = proxy.send_event(Message::Webview( + id, + WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)), + )); + Ok(()) + })), + &mut token, + ) + } + .unwrap(); let proxy = self.event_loop.create_proxy(); - controller - .add_lost_focus(move |_| { - let _ = proxy.send_event(Message::Webview( - id, - WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)), - )); - Ok(()) - }) - .unwrap(); + unsafe { + controller.add_LostFocus( + FocusChangedEventHandler::create(Box::new(move |_, _| { + let _ = proxy.send_event(Message::Webview( + id, + WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)), + )); + Ok(()) + })), + &mut token, + ) + } + .unwrap(); } } } @@ -2024,7 +2036,7 @@ fn handle_event_loop( #[cfg(target_os = "macos")] WindowMessage::NSWindow(tx) => tx.send(NSWindow(window.ns_window())).unwrap(), #[cfg(windows)] - WindowMessage::Hwnd(tx) => tx.send(Hwnd(window.hwnd() as HWND)).unwrap(), + WindowMessage::Hwnd(tx) => tx.send(Hwnd(HWND(window.hwnd() as _))).unwrap(), #[cfg(any( target_os = "linux", target_os = "dragonfly", diff --git a/core/tauri-runtime/Cargo.toml b/core/tauri-runtime/Cargo.toml index b4e75534b..f8a8ddb59 100644 --- a/core/tauri-runtime/Cargo.toml +++ b/core/tauri-runtime/Cargo.toml @@ -32,7 +32,7 @@ http-range = "0.1.4" infer = "0.4" [target."cfg(windows)".dependencies] -winapi = "0.3" +webview2-com-sys = "0.4.0" [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] gtk = { version = "0.14", features = [ "v3_20" ] } diff --git a/core/tauri-runtime/src/lib.rs b/core/tauri-runtime/src/lib.rs index e9d5c47ab..b5eeddc6f 100644 --- a/core/tauri-runtime/src/lib.rs +++ b/core/tauri-runtime/src/lib.rs @@ -11,7 +11,7 @@ use std::{fmt::Debug, path::PathBuf, sync::mpsc::Sender}; use uuid::Uuid; #[cfg(windows)] -use winapi::shared::windef::HWND; +use webview2_com_sys::Windows::Win32::Foundation::HWND; pub mod http; /// Create window and system tray menus. diff --git a/core/tauri-runtime/src/webview.rs b/core/tauri-runtime/src/webview.rs index d1b181282..36b2f16b2 100644 --- a/core/tauri-runtime/src/webview.rs +++ b/core/tauri-runtime/src/webview.rs @@ -13,7 +13,7 @@ use serde_json::Value as JsonValue; use tauri_utils::config::{WindowConfig, WindowUrl}; #[cfg(windows)] -use winapi::shared::windef::HWND; +use webview2_com_sys::Windows::Win32::Foundation::HWND; use std::{fmt, path::PathBuf}; diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 3a7b8aa65..c5fa4e966 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -526,7 +526,7 @@ impl Window { .window .dispatcher .hwnd() - .map(|hwnd| hwnd as *mut _) + .map(|hwnd| hwnd.0 as *mut _) .map_err(Into::into) } diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index b1c66fe9f..0aab49fbc 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -393,37 +393,6 @@ dependencies = [ "objc", ] -[[package]] -name = "com" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a30a2b2a013da986dc5cc3eda3d19c0d59d53f835be1b2356eb8d00f000c793" -dependencies = [ - "com_macros", -] - -[[package]] -name = "com_macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7606b05842fea68ddcc89e8053b8860ebcb2a0ba8d6abfe3a148e5d5a8d3f0c1" -dependencies = [ - "com_macros_support", - "proc-macro2", - "syn 1.0.76", -] - -[[package]] -name = "com_macros_support" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97e9a6d20f4ac8830e309a455d7e9416e65c6af5a97c88c55fbb4c2012e107da" -dependencies = [ - "proc-macro2", - "quote 1.0.9", - "syn 1.0.76", -] - [[package]] name = "concurrent-queue" version = "1.2.2" @@ -433,6 +402,12 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "const-sha1" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -2853,8 +2828,7 @@ dependencies = [ [[package]] name = "tao" version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aa57de7c282b68f8906278543a724ed8f5a2568f069dd0cc05fc10d1f07036b" +source = "git+https://github.com/tauri-apps/tao?branch=next#e1e9b61993e18422efa7810a17ed1aaa2000621a" dependencies = [ "bitflags 1.3.2", "cairo-rs", @@ -2886,7 +2860,8 @@ dependencies = [ "serde", "tauri-libappindicator", "unicode-segmentation", - "winapi", + "webview2-com-sys", + "windows", "x11-dl", ] @@ -3022,7 +2997,7 @@ dependencies = [ "tauri-utils", "thiserror", "uuid", - "winapi", + "webview2-com-sys", ] [[package]] @@ -3036,7 +3011,7 @@ dependencies = [ "tauri-runtime", "tauri-utils", "uuid", - "winapi", + "webview2-com", "wry", ] @@ -3057,19 +3032,6 @@ dependencies = [ "zstd", ] -[[package]] -name = "tauri-webview2" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7685d17e9007618d13f011f916e28a8830c7108c46cf263bd3ab53a19e1a4fc3" -dependencies = [ - "com", - "once_cell", - "webview2-sys", - "widestring", - "winapi", -] - [[package]] name = "tempfile" version = "3.2.0" @@ -3462,13 +3424,38 @@ dependencies = [ ] [[package]] -name = "webview2-sys" -version = "0.1.1" +name = "webview2-com" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24b7889e893ac4c50d7346356be3ce13a85e56512c38b8fde0526559b8012a4c" +checksum = "f2294dee38668da0d71019097dddc6cef525fde7aa4784243dd83f0752e08aa5" dependencies = [ - "com", - "winapi", + "webview2-com-macros", + "webview2-com-sys", + "windows", +] + +[[package]] +name = "webview2-com-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eba35fdbb8fbc8de7e7479532a356dbbf2754d8a6e9c9fbfa430896cbb1ca89" +dependencies = [ + "proc-macro2", + "quote 1.0.9", + "syn 1.0.76", +] + +[[package]] +name = "webview2-com-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14690dcb8b57c5238c4502cfc321f858fa1306edd4109e8e1d7ddee0c29b06a5" +dependencies = [ + "regex", + "serde", + "serde_json", + "thiserror", + "windows", ] [[package]] @@ -3480,12 +3467,6 @@ dependencies = [ "cc", ] -[[package]] -name = "widestring" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" - [[package]] name = "wildmatch" version = "1.1.0" @@ -3523,6 +3504,51 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef84dd25f4c69a271b1bba394532bf400523b43169de21dfc715e8f8e491053d" +dependencies = [ + "const-sha1", + "windows_gen", + "windows_macros", +] + +[[package]] +name = "windows_gen" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac7bb21b8ff5e801232b72a6ff554b4cc0cef9ed9238188c3ca78fe3968a7e5d" +dependencies = [ + "windows_quote", + "windows_reader", +] + +[[package]] +name = "windows_macros" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5566b8c51118769e4a9094a688bf1233a3f36aacbfc78f3b15817fe0b6e0442f" +dependencies = [ + "syn 1.0.76", + "windows_gen", + "windows_quote", + "windows_reader", +] + +[[package]] +name = "windows_quote" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4af8236a9493c38855f95cdd11b38b342512a5df4ee7473cffa828b5ebb0e39c" + +[[package]] +name = "windows_reader" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d5cf83fb08083438c5c46723e6206b2970da57ce314f80b57724439aaacab" + [[package]] name = "winres" version = "0.1.11" @@ -3557,7 +3583,7 @@ dependencies = [ [[package]] name = "wry" version = "0.12.2" -source = "git+https://github.com/tauri-apps/wry?rev=21692d986138570d2edc31f84bddb442a3c84a9c#21692d986138570d2edc31f84bddb442a3c84a9c" +source = "git+https://github.com/tauri-apps/wry?rev=e056fb2a15e29de1b8ed85a548cfeb1f85031357#e056fb2a15e29de1b8ed85a548cfeb1f85031357" dependencies = [ "cocoa", "core-graphics 0.22.2", @@ -3574,13 +3600,12 @@ dependencies = [ "serde", "serde_json", "tao", - "tauri-webview2", "thiserror", "url", "webkit2gtk", "webkit2gtk-sys", - "webview2-sys", - "winapi", + "webview2-com", + "windows", ] [[package]]