From 869c2fa67e75c84b6587ba10fb2de74cab945364 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 27 Aug 2022 14:19:15 +0200 Subject: [PATCH 1/8] refactor: remove unneeded focus code --- core/tauri-runtime-wry/src/lib.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 2b0a66ccca45..631a59598bae 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -2673,22 +2673,6 @@ fn handle_event_loop( event, window_id, .. } => { let window_id = webview_id_map.get(&window_id); - // NOTE(amrbashir): we handle this event here instead of `match` statement below because - // we want to focus the webview as soon as possible, especially on windows. - if event == WryWindowEvent::Focused(true) { - let w = windows - .borrow() - .get(&window_id) - .and_then(|w| w.inner.clone()); - if let Some(WindowHandle::Webview(webview)) = w { - // only focus the webview if the window is visible - // somehow tao is sending a Focused(true) event even when the window is invisible, - // which causes a deadlock: https://github.com/tauri-apps/tauri/issues/3534 - if webview.window().is_visible() { - webview.focus(); - } - } - } { let windows_ref = windows.borrow(); From f58b25b2654a31700fa68bea99a45fe1c8a971aa Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 27 Aug 2022 14:20:49 +0200 Subject: [PATCH 2/8] use wry git version --- core/tauri-runtime-wry/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tauri-runtime-wry/Cargo.toml b/core/tauri-runtime-wry/Cargo.toml index 5780814d4783..0ecb85fee4f1 100644 --- a/core/tauri-runtime-wry/Cargo.toml +++ b/core/tauri-runtime-wry/Cargo.toml @@ -13,7 +13,7 @@ exclude = [ ".license_template", "CHANGELOG.md", "/target" ] readme = "README.md" [dependencies] -wry = { version = "0.20", default-features = false, features = [ "file-drop", "protocol" ] } +wry = { git = "https://github.com/tauri-apps/wry", branch = "auto-focus",default-features = false, features = [ "file-drop", "protocol" ] } tauri-runtime = { version = "0.10.2", path = "../tauri-runtime" } tauri-utils = { version = "1.0.3", path = "../tauri-utils" } uuid = { version = "1", features = [ "v4" ] } From 8f72144abdc5240e515b407a73275a689c6c02ca Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 2 Sep 2022 20:29:17 -0300 Subject: [PATCH 3/8] feat: update windows and webview2-com --- .changes/windows-update.md | 8 ++ core/tauri-runtime-wry/Cargo.toml | 6 +- core/tauri-runtime/Cargo.toml | 4 +- core/tauri-utils/Cargo.toml | 3 +- core/tauri/Cargo.toml | 2 +- examples/api/src-tauri/Cargo.lock | 153 +++++++++++++++++++++++++----- 6 files changed, 145 insertions(+), 31 deletions(-) create mode 100644 .changes/windows-update.md diff --git a/.changes/windows-update.md b/.changes/windows-update.md new file mode 100644 index 000000000000..3a07f1d16080 --- /dev/null +++ b/.changes/windows-update.md @@ -0,0 +1,8 @@ +--- +"tauri-runtime-wry": minor +"tauri-runtime": minor +"tauri-utils": minor +"tauri": minor +--- + +Update windows to 0.39.0 and webview2-com to 0.19.1. diff --git a/core/tauri-runtime-wry/Cargo.toml b/core/tauri-runtime-wry/Cargo.toml index 0ecb85fee4f1..707d2e70bd5e 100644 --- a/core/tauri-runtime-wry/Cargo.toml +++ b/core/tauri-runtime-wry/Cargo.toml @@ -13,7 +13,7 @@ exclude = [ ".license_template", "CHANGELOG.md", "/target" ] readme = "README.md" [dependencies] -wry = { git = "https://github.com/tauri-apps/wry", branch = "auto-focus",default-features = false, features = [ "file-drop", "protocol" ] } +wry = { git = "https://github.com/tauri-apps/wry", branch = "dev", default-features = false, features = [ "file-drop", "protocol" ] } tauri-runtime = { version = "0.10.2", path = "../tauri-runtime" } tauri-utils = { version = "1.0.3", path = "../tauri-utils" } uuid = { version = "1", features = [ "v4" ] } @@ -21,10 +21,10 @@ rand = "0.8" raw-window-handle = "0.5" [target."cfg(windows)".dependencies] -webview2-com = "0.16.0" +webview2-com = "0.19.1" [target."cfg(windows)".dependencies.windows] - version = "0.37.0" + version = "0.39.0" features = [ "Win32_Foundation" ] [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] diff --git a/core/tauri-runtime/Cargo.toml b/core/tauri-runtime/Cargo.toml index bcd81972e193..376fc2b8ca00 100644 --- a/core/tauri-runtime/Cargo.toml +++ b/core/tauri-runtime/Cargo.toml @@ -35,10 +35,10 @@ raw-window-handle = "0.5" rand = "0.8" [target."cfg(windows)".dependencies] -webview2-com = "0.16.0" +webview2-com = "0.19.1" [target."cfg(windows)".dependencies.windows] - version = "0.37.0" + version = "0.39.0" features = [ "Win32_Foundation" ] [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] diff --git a/core/tauri-utils/Cargo.toml b/core/tauri-utils/Cargo.toml index 1c59d5a65704..6c886c4c3dd2 100644 --- a/core/tauri-utils/Cargo.toml +++ b/core/tauri-utils/Cargo.toml @@ -40,9 +40,8 @@ semver = "1" heck = "0.4" [target."cfg(windows)".dependencies.windows] -version = "0.37.0" +version = "0.39.0" features = [ - "alloc", "implement", "Win32_Foundation", "Win32_System_Com", diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index d11edae250c1..ccf8e341a705 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -112,7 +112,7 @@ webview2-com = "0.16.0" win7-notifications = { version = "0.3.0", optional = true } [target."cfg(windows)".dependencies.windows] -version = "0.37.0" +version = "0.39.0" features = [ "Win32_Foundation" ] [build-dependencies] diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index b9dddd963805..fa66320b9476 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3089,9 +3089,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad691ca9fca6c2c76c09ffcddf6ae6593fba65d95477cf31780910ed272f5b8" +checksum = "a2093fa6bba3cc0c185b21c900de1b757e66637e78848cbcdda967b836d8c0ec" dependencies = [ "bitflags", "cairo-rs", @@ -3131,7 +3131,7 @@ dependencies = [ "unicode-segmentation", "uuid 1.1.2", "windows 0.37.0", - "windows-implement", + "windows-implement 0.37.0", "x11-dl", ] @@ -3203,9 +3203,9 @@ dependencies = [ "url", "uuid 1.1.2", "webkit2gtk", - "webview2-com", + "webview2-com 0.16.0", "win7-notifications", - "windows 0.37.0", + "windows 0.39.0", "zip", ] @@ -3276,8 +3276,8 @@ dependencies = [ "tauri-utils", "thiserror", "uuid 1.1.2", - "webview2-com", - "windows 0.37.0", + "webview2-com 0.19.1", + "windows 0.39.0", ] [[package]] @@ -3293,8 +3293,8 @@ dependencies = [ "tauri-utils", "uuid 1.1.2", "webkit2gtk", - "webview2-com", - "windows 0.37.0", + "webview2-com 0.19.1", + "windows 0.39.0", "wry", ] @@ -3323,7 +3323,7 @@ dependencies = [ "thiserror", "url", "walkdir", - "windows 0.37.0", + "windows 0.39.0", ] [[package]] @@ -3872,9 +3872,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a489a9420acabb3c2ed0434b6f71f6b56b9485ec32665a28dec1ee186d716e0f" dependencies = [ "webview2-com-macros", - "webview2-com-sys", + "webview2-com-sys 0.16.0", "windows 0.37.0", - "windows-implement", + "windows-implement 0.37.0", +] + +[[package]] +name = "webview2-com" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a769c9f1a64a8734bde70caafac2b96cada12cd4aefa49196b3a386b8b4178" +dependencies = [ + "webview2-com-macros", + "webview2-com-sys 0.19.0", + "windows 0.39.0", + "windows-implement 0.39.0", ] [[package]] @@ -3899,7 +3911,22 @@ dependencies = [ "serde_json", "thiserror", "windows 0.37.0", - "windows-bindgen", + "windows-bindgen 0.37.0", +] + +[[package]] +name = "webview2-com-sys" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aac48ef20ddf657755fdcda8dfed2a7b4fc7e4581acce6fe9b88c3d64f29dee7" +dependencies = [ + "regex", + "serde", + "serde_json", + "thiserror", + "windows 0.39.0", + "windows-bindgen 0.39.0", + "windows-metadata 0.39.0", ] [[package]] @@ -4004,7 +4031,7 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" dependencies = [ - "windows-implement", + "windows-implement 0.37.0", "windows_aarch64_msvc 0.37.0", "windows_i686_gnu 0.37.0", "windows_i686_msvc 0.37.0", @@ -4012,14 +4039,38 @@ dependencies = [ "windows_x86_64_msvc 0.37.0", ] +[[package]] +name = "windows" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" +dependencies = [ + "windows-implement 0.39.0", + "windows_aarch64_msvc 0.39.0", + "windows_i686_gnu 0.39.0", + "windows_i686_msvc 0.39.0", + "windows_x86_64_gnu 0.39.0", + "windows_x86_64_msvc 0.39.0", +] + [[package]] name = "windows-bindgen" version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bed7be31ade0af08fec9b5343e9edcc005d22b1f11859b8a59b24797f5858e8" dependencies = [ - "windows-metadata", - "windows-tokens", + "windows-metadata 0.37.0", + "windows-tokens 0.37.0", +] + +[[package]] +name = "windows-bindgen" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68003dbd0e38abc0fb85b939240f4bce37c43a5981d3df37ccbaaa981b47cb41" +dependencies = [ + "windows-metadata 0.39.0", + "windows-tokens 0.39.0", ] [[package]] @@ -4029,7 +4080,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67a1062e555f7d9d66fd1130ed4f7c6ec41a47529ee0850cd0e926d95b26bb14" dependencies = [ "syn", - "windows-tokens", + "windows-tokens 0.37.0", +] + +[[package]] +name = "windows-implement" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba01f98f509cb5dc05f4e5fc95e535f78260f15fea8fe1a8abdd08f774f1cee7" +dependencies = [ + "syn", + "windows-tokens 0.39.0", ] [[package]] @@ -4038,6 +4099,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f33f2b90a6664e369c41ab5ff262d06f048fc9685d9bf8a0e99a47750bb0463" +[[package]] +name = "windows-metadata" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee5e275231f07c6e240d14f34e1b635bf1faa1c76c57cfd59a5cdb9848e4278" + [[package]] name = "windows-sys" version = "0.36.1" @@ -4057,6 +4124,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3263d25f1170419995b78ff10c06b949e8a986c35c208dc24333c64753a87169" +[[package]] +name = "windows-tokens" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f838de2fe15fe6bac988e74b798f26499a8b21a9d97edec321e79b28d1d7f597" + [[package]] name = "windows_aarch64_msvc" version = "0.32.0" @@ -4075,6 +4148,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" +[[package]] +name = "windows_aarch64_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" + [[package]] name = "windows_i686_gnu" version = "0.24.0" @@ -4099,6 +4178,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" +[[package]] +name = "windows_i686_gnu" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" + [[package]] name = "windows_i686_msvc" version = "0.24.0" @@ -4123,6 +4208,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" +[[package]] +name = "windows_i686_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" + [[package]] name = "windows_x86_64_gnu" version = "0.24.0" @@ -4147,6 +4238,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" +[[package]] +name = "windows_x86_64_gnu" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" + [[package]] name = "windows_x86_64_msvc" version = "0.24.0" @@ -4171,6 +4268,12 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" + [[package]] name = "winreg" version = "0.10.1" @@ -4202,18 +4305,21 @@ dependencies = [ [[package]] name = "wry" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a806297d9fae9fef5a9d52480e5edc5452f97ea9d15b55c8a58ab93c9582f1" +version = "0.20.2" +source = "git+https://github.com/tauri-apps/wry?branch=dev#854d2226f4161d4fc783f64e79b6a8add31ac4eb" dependencies = [ + "base64", "block", "cocoa", "core-graphics", + "crossbeam-channel", "gdk", "gio", "glib", "gtk", + "html5ever", "http", + "kuchiki", "libc", "log", "objc", @@ -4221,14 +4327,15 @@ dependencies = [ "once_cell", "serde", "serde_json", + "sha2", "tao", "thiserror", "url", "webkit2gtk", "webkit2gtk-sys", - "webview2-com", - "windows 0.37.0", - "windows-implement", + "webview2-com 0.19.1", + "windows 0.39.0", + "windows-implement 0.39.0", ] [[package]] From 4fab508200fdc39076bdb40580b82235b4ff6018 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 2 Sep 2022 21:04:07 -0300 Subject: [PATCH 4/8] fix windows_version --- core/tauri-utils/src/platform.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/core/tauri-utils/src/platform.rs b/core/tauri-utils/src/platform.rs index 75ebab4ba234..6d811ba8ab10 100644 --- a/core/tauri-utils/src/platform.rs +++ b/core/tauri-utils/src/platform.rs @@ -202,11 +202,14 @@ pub use windows_platform::{is_windows_7, windows_version}; #[cfg(windows)] mod windows_platform { - use windows::Win32::{ - Foundation::FARPROC, - System::{ - LibraryLoader::{GetProcAddress, LoadLibraryA}, - SystemInformation::OSVERSIONINFOW, + use windows::{ + core::{PCSTR, PCWSTR}, + Win32::{ + Foundation::FARPROC, + System::{ + LibraryLoader::{GetProcAddress, LoadLibraryW}, + SystemInformation::OSVERSIONINFOW, + }, }, }; @@ -221,11 +224,19 @@ mod windows_platform { false } + fn encode_wide(string: impl AsRef) -> Vec { + string.as_ref().encode_wide().chain(once(0)).collect() + } + + // Helper function to dynamically load function pointer. + // `library` and `function` must be zero-terminated. fn get_function_impl(library: &str, function: &str) -> Option { - assert_eq!(library.chars().last(), Some('\0')); + let library = encode_wide(library); assert_eq!(function.chars().last(), Some('\0')); + let function = PCSTR::from_raw(function.as_ptr()); - let module = unsafe { LoadLibraryA(library) }.unwrap_or_default(); + // Library names we will use are ASCII so we can use the A version to avoid string conversion. + let module = unsafe { LoadLibraryW(PCWSTR::from_raw(library.as_ptr())) }.unwrap_or_default(); if module.is_invalid() { None } else { From e172c264ce04786a4b72146012a5c106fdc267b8 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 3 Sep 2022 00:42:59 -0300 Subject: [PATCH 5/8] add missing imports --- core/tauri-utils/src/platform.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/tauri-utils/src/platform.rs b/core/tauri-utils/src/platform.rs index 6d811ba8ab10..6393e96e1e79 100644 --- a/core/tauri-utils/src/platform.rs +++ b/core/tauri-utils/src/platform.rs @@ -202,6 +202,7 @@ pub use windows_platform::{is_windows_7, windows_version}; #[cfg(windows)] mod windows_platform { + use std::{iter::once, os::windows::prelude::OsStrExt}; use windows::{ core::{PCSTR, PCWSTR}, Win32::{ From c3c00e0216bf9ed7162f4adf03301c7d04bd11c0 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 3 Sep 2022 12:57:49 +0200 Subject: [PATCH 6/8] fix webview2 errors --- core/tauri-runtime-wry/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 4ace2fa2454f..2ebc42de5ca0 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -2963,7 +2963,7 @@ fn create_webview( let mut token = EventRegistrationToken::default(); unsafe { controller.add_GotFocus( - FocusChangedEventHandler::create(Box::new(move |_, _| { + &FocusChangedEventHandler::create(Box::new(move |_, _| { let _ = proxy_.send_event(Message::Webview( window_id, WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)), @@ -2976,7 +2976,7 @@ fn create_webview( .unwrap(); unsafe { controller.add_LostFocus( - FocusChangedEventHandler::create(Box::new(move |_, _| { + &FocusChangedEventHandler::create(Box::new(move |_, _| { let _ = proxy.send_event(Message::Webview( window_id, WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)), From a7c9dd203ea700e0f01a3c462815dde9d2b9112d Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 3 Sep 2022 09:39:46 -0300 Subject: [PATCH 7/8] use tao from git --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 53de27cd06d3..81e0b560a737 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,3 +29,6 @@ codegen-units = 1 lto = true incremental = false opt-level = "s" + +[patch.crates-io] +tao = { git = "https://github.com/tauri-apps/tao", branch = "dev" } From 622889e1290d532d47ec34b4706a946d6fde6d42 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 3 Sep 2022 09:40:52 -0300 Subject: [PATCH 8/8] fix webview2-com version --- core/tauri/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index e8fcdc5eda83..b8636708b08a 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -107,7 +107,7 @@ cocoa = "0.24" objc = "0.2" [target."cfg(windows)".dependencies] -webview2-com = "0.16.0" +webview2-com = "0.19.1" win7-notifications = { version = "0.3.0", optional = true } [target."cfg(windows)".dependencies.windows]