From c696d0d0746d0dd8871880f42de62dbeafa84a70 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 27 Nov 2023 14:47:16 +0900 Subject: [PATCH] upgrade wry to v0.35 and introduce tao v0.24 --- v2/Cargo.lock | 239 ++++++++++++++++++--------------------- v2/Cargo.toml | 7 +- v2/src/wry/event_loop.rs | 6 +- v2/src/wry/menu.rs | 8 +- v2/src/wry/webview.rs | 70 ++++++------ 5 files changed, 155 insertions(+), 175 deletions(-) diff --git a/v2/Cargo.lock b/v2/Cargo.lock index f8bcf66..c4755e7 100644 --- a/v2/Cargo.lock +++ b/v2/Cargo.lock @@ -60,12 +60,12 @@ dependencies = [ [[package]] name = "async-channel" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37875bd9915b7d67c2f117ea2c30a0989874d0b2cb694fe25403c85763c0c9e" +checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" dependencies = [ "concurrent-queue", - "event-listener 3.1.0", + "event-listener 4.0.0", "event-listener-strategy", "futures-core", "pin-project-lite", @@ -73,11 +73,11 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5ea910c42e5ab19012bab31f53cb4d63d54c3a27730f9a833a88efcf4bb52d" +checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ - "async-lock 3.1.1", + "async-lock 3.1.2", "async-task", "concurrent-queue", "fastrand 2.0.1", @@ -119,22 +119,21 @@ dependencies = [ [[package]] name = "async-io" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9d5715c2d329bf1b4da8d60455b99b187f27ba726df2883799af9af60997" +checksum = "d6d3b15875ba253d1110c740755e246537483f152fa334f91abd7fe84c88b3ff" dependencies = [ - "async-lock 3.1.1", + "async-lock 3.1.2", "cfg-if", "concurrent-queue", "futures-io", "futures-lite 2.0.1", "parking", - "polling 3.3.0", + "polling 3.3.1", "rustix 0.38.25", "slab", "tracing", - "waker-fn", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -148,11 +147,11 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.1.1" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "655b9c7fe787d3b25cc0f804a1a8401790f0c5bc395beb5a64dc77d8de079105" +checksum = "dea8b3453dd7cc96711834b75400d671b73e3656975fa68d9f277163b7f7e316" dependencies = [ - "event-listener 3.1.0", + "event-listener 4.0.0", "event-listener-strategy", "pin-project-lite", ] @@ -191,7 +190,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" dependencies = [ - "async-io 2.2.0", + "async-io 2.2.1", "async-lock 2.8.0", "atomic-waker", "cfg-if", @@ -298,7 +297,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ "async-channel", - "async-lock 3.1.1", + "async-lock 3.1.2", "async-task", "fastrand 2.0.1", "futures-io", @@ -393,6 +392,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "ciborium" version = "0.2.1" @@ -445,22 +450,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" -[[package]] -name = "cocoa" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" -dependencies = [ - "bitflags 1.3.2", - "block", - "cocoa-foundation", - "core-foundation", - "core-graphics 0.22.3", - "foreign-types 0.3.2", - "libc", - "objc", -] - [[package]] name = "cocoa" version = "0.25.0" @@ -471,8 +460,8 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics 0.23.1", - "foreign-types 0.5.0", + "core-graphics", + "foreign-types", "libc", "objc", ] @@ -550,19 +539,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "core-graphics" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", - "foreign-types 0.3.2", - "libc", -] - [[package]] name = "core-graphics" version = "0.23.1" @@ -572,7 +548,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -891,13 +867,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "event-listener" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + [[package]] name = "event-listener-strategy" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96b852f1345da36d551b9473fa1e2b1eb5c5195585c6c018118bc92a8d91160" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ - "event-listener 3.1.0", + "event-listener 4.0.0", "pin-project-lite", ] @@ -963,15 +950,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -979,7 +957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -993,12 +971,6 @@ dependencies = [ "syn 2.0.39", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -1007,9 +979,9 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -1215,6 +1187,20 @@ dependencies = [ "system-deps", ] +[[package]] +name = "gdkx11" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2ea8a4909d530f79921290389cbd7c34cb9d623bfe970eaae65ca5f9cd9cce" +dependencies = [ + "gdk", + "gdkx11-sys", + "gio", + "glib", + "libc", + "x11", +] + [[package]] name = "gdkx11-sys" version = "0.18.0" @@ -1416,9 +1402,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -1471,9 +1457,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1509,7 +1495,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.3", ] [[package]] @@ -1890,7 +1876,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9767ce3b12d2928f17ff4f91b29e7e872a8594033d82bf00e56017cc23bb8410" dependencies = [ - "cocoa 0.25.0", + "cocoa", "crossbeam-channel", "gtk", "keyboard-types", @@ -2078,9 +2064,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "open" -version = "5.0.0" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfabf1927dce4d6fdf563d63328a0a506101ced3ec780ca2135747336c98cef8" +checksum = "90878fb664448b54c4e592455ad02831e23a3f7e157374a8b95654731aac7349" dependencies = [ "is-wsl", "libc", @@ -2165,9 +2151,9 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" @@ -2391,16 +2377,16 @@ dependencies = [ [[package]] name = "polling" -version = "3.3.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +checksum = "cf63fa624ab313c11656b4cda960bfc46c410187ad493c41f6ba2d8c1e991c9e" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", "rustix 0.38.25", "tracing", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2466,9 +2452,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -2892,8 +2878,9 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "tao", "window-vibrancy", - "windows-sys 0.48.0", + "windows-sys 0.52.0", "winresource", "wry", ] @@ -3051,26 +3038,19 @@ dependencies = [ [[package]] name = "tao" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f130523fee9820ad78141d443e6cef75043acade79107bc483872bc183928c0f" +checksum = "3c0dff18fed076d29cb5779e918ef4b8a5dbb756204e4a027794f0bce233d949" dependencies = [ "bitflags 1.3.2", - "cairo-rs", "cc", - "cocoa 0.24.1", + "cocoa", "core-foundation", - "core-graphics 0.22.3", + "core-graphics", "crossbeam-channel", "dispatch", - "gdk", - "gdk-pixbuf", - "gdk-sys", "gdkwayland-sys", "gdkx11-sys", - "gio", - "glib", - "glib-sys", "gtk", "image", "instant", @@ -3087,13 +3067,12 @@ dependencies = [ "png", "raw-window-handle", "scopeguard", - "serde", "tao-macros", "unicode-segmentation", "url", - "uuid", "windows", "windows-implement", + "windows-version", "x11-dl", "zbus", ] @@ -3346,9 +3325,9 @@ checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -3361,15 +3340,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "uuid" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" -dependencies = [ - "getrandom 0.2.11", -] - [[package]] name = "version-compare" version = "0.1.1" @@ -3532,9 +3502,9 @@ dependencies = [ [[package]] name = "webview2-com" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15556ff1d1d6bc850dbb362762bae86069773dd30177c90d3bfa917080dc73" +checksum = "e0ae9c7e420783826cf769d2c06ac9ba462f450eca5893bb8c6c6529a4e5dd33" dependencies = [ "webview2-com-macros", "webview2-com-sys", @@ -3557,9 +3527,9 @@ dependencies = [ [[package]] name = "webview2-com-sys" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3775bb005c3170497ec411b36005708b57ad486bfa3d23864c92f5973858ce8d" +checksum = "d6ad85fceee6c42fa3d61239eba5a11401bf38407a849ed5ea1b407df08cca72" dependencies = [ "thiserror", "windows", @@ -3603,7 +3573,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af6abc2b9c56bd95887825a1ce56cde49a2a97c07e28db465d541f5098a2656c" dependencies = [ - "cocoa 0.25.0", + "cocoa", "objc", "raw-window-handle", "windows-sys 0.52.0", @@ -3612,30 +3582,30 @@ dependencies = [ [[package]] name = "windows" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core", "windows-implement", "windows-interface", - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] name = "windows-implement" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb2b158efec5af20d8846836622f50a87e6556b9153a42772fa047f773c0e555" +checksum = "12168c33176773b86799be25e2a2ba07c7aab9968b37541f1094dbd7a60c8946" dependencies = [ "proc-macro2", "quote", @@ -3644,9 +3614,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0546e63e1ce64c04403d2311fa0e3ab5ae3a367bd524b4a38d8d8d18c70cfa76" +checksum = "9d8dc32e0095a7eeccebd0e3f09e9509365ecb3fc6ac4d6f5f14a3f6392942d1" dependencies = [ "proc-macro2", "quote", @@ -3880,31 +3850,38 @@ dependencies = [ [[package]] name = "wry" -version = "0.34.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f1e29660f22d8eec141f41f59b7fef231e4113c370c89b90ae3a0db8dec1927" +checksum = "764ce8212721205a90c79f5fa04f5135af597bea9072f22a5e7f39dcd0669f2e" dependencies = [ "base64", "block", - "cocoa 0.25.0", - "core-graphics 0.23.1", + "cfg_aliases", + "cocoa", + "core-graphics", "crossbeam-channel", "dunce", + "gdkx11", "gtk", "html5ever", "http", "javascriptcore-rs", + "jni", "kuchikiki", "libc", "log", + "ndk", + "ndk-context", + "ndk-sys", "objc", "objc_id", "once_cell", + "raw-window-handle", "serde", "serde_json", "sha2", "soup3", - "tao", + "tao-macros", "thiserror", "url", "webkit2gtk", @@ -3912,6 +3889,8 @@ dependencies = [ "webview2-com", "windows", "windows-implement", + "windows-version", + "x11-dl", ] [[package]] diff --git a/v2/Cargo.toml b/v2/Cargo.toml index 109dc76..f4a12c2 100644 --- a/v2/Cargo.toml +++ b/v2/Cargo.toml @@ -47,16 +47,17 @@ rfd = "0.12.1" # 0.12.0 is incompatible with wry because of gtk-sys version serde = "1.0.190" serde_json = "1.0.107" serde_yaml = "0.9.27" +tao = { version = "0.24", default-features = false, features = [ "rwh_05" ] } [target.'cfg(target_os = "macos")'.dependencies] -wry = { version = "0.34.2", features = ["transparent"] } +wry = { version = "0.35.0", features = ["transparent"] } window-vibrancy = "0.4.2" [target.'cfg(not(target_os = "macos"))'.dependencies] -wry = "0.34.2" +wry = "0.35.0" [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.48.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_WindowsAndMessaging"] } +windows-sys = { version = "0.52.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_WindowsAndMessaging"] } [dev-dependencies] insta = { version = "1.34.0", features = ["json"] } diff --git a/v2/src/wry/event_loop.rs b/v2/src/wry/event_loop.rs index 21ea5cf..7e7a540 100644 --- a/v2/src/wry/event_loop.rs +++ b/v2/src/wry/event_loop.rs @@ -3,8 +3,8 @@ use crate::renderer::{EventHandler, Rendering, RenderingFlow, UserEvent, UserEve use crate::wry::menu::{Menu, MenuEvents}; use crate::wry::webview::{EventLoop, WebViewRenderer}; use anyhow::Result; -use wry::application::event::{Event, StartCause, WindowEvent}; -use wry::application::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy}; +use tao::event::{Event, StartCause, WindowEvent}; +use tao::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy}; pub struct Wry { event_loop: EventLoop, @@ -34,8 +34,8 @@ impl Rendering for Wry { #[cfg(windows)] fn new() -> Result { + use tao::platform::windows::EventLoopBuilderExtWindows; use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG}; - use wry::application::platform::windows::EventLoopBuilderExtWindows; let mut menu_events = MenuEvents::new(); let menu = Menu::new(&mut menu_events)?; diff --git a/v2/src/wry/menu.rs b/v2/src/wry/menu.rs index bf27e8b..89e7162 100644 --- a/v2/src/wry/menu.rs +++ b/v2/src/wry/menu.rs @@ -8,12 +8,12 @@ use muda::{ use std::collections::hash_map::Entry; use std::collections::HashMap; #[cfg(target_os = "macos")] -use wry::application::platform::macos::WindowExtMacOS as _; +use tao::platform::macos::WindowExtMacOS as _; #[cfg(target_os = "linux")] -use wry::application::platform::unix::WindowExtUnix as _; +use tao::platform::unix::WindowExtUnix as _; #[cfg(target_os = "windows")] -use wry::application::platform::windows::WindowExtWindows as _; -use wry::application::window::{Window, WindowId}; +use tao::platform::windows::WindowExtWindows as _; +use tao::window::{Window, WindowId}; fn metadata() -> AboutMetadata { let mut m = AboutMetadata { diff --git a/v2/src/wry/webview.rs b/v2/src/wry/webview.rs index f85d983..ef38404 100644 --- a/v2/src/wry/webview.rs +++ b/v2/src/wry/webview.rs @@ -7,17 +7,17 @@ use crate::renderer::{ }; use crate::wry::menu::Menu; use anyhow::{Context as _, Result}; -use wry::application::dpi::{PhysicalPosition, PhysicalSize}; +use tao::dpi::{PhysicalPosition, PhysicalSize}; #[cfg(target_os = "macos")] -use wry::application::platform::macos::WindowBuilderExtMacOS as _; -use wry::application::window::{Fullscreen, Theme, Window, WindowBuilder}; +use tao::platform::macos::WindowBuilderExtMacOS as _; +use tao::window::{Fullscreen, Theme, Window, WindowBuilder}; use wry::http::header::CONTENT_TYPE; use wry::http::Response; #[cfg(target_os = "windows")] -use wry::webview::WebViewBuilderExtWindows; -use wry::webview::{FileDropEvent, WebContext, WebView, WebViewBuilder}; +use wry::WebViewBuilderExtWindows; +use wry::{FileDropEvent, WebContext, WebView, WebViewBuilder}; -pub type EventLoop = wry::application::event_loop::EventLoop; +pub type EventLoop = tao::event_loop::EventLoop; #[cfg(not(target_os = "macos"))] const ICON_RGBA: &[u8] = include_bytes!("../assets/icon_32x32.rgba"); @@ -33,32 +33,32 @@ fn window_theme(window: &Window) -> RendererTheme { } } -fn create_webview(window: Window, event_loop: &EventLoop, config: &Config) -> Result { +fn create_webview(window: &Window, event_loop: &EventLoop, config: &Config) -> Result { let ipc_proxy = event_loop.create_proxy(); let file_drop_proxy = event_loop.create_proxy(); let navigation_proxy = event_loop.create_proxy(); - let loader = Assets::new(config, window_theme(&window)); + let loader = Assets::new(config, window_theme(window)); let user_dir = config.data_dir().path().map(|dir| dir.join("WebView")); log::debug!("WebView user data directory: {:?}", user_dir); let mut context = WebContext::new(user_dir); #[allow(unused_mut)] - let mut builder = WebViewBuilder::new(window)? + let mut builder = WebViewBuilder::new(window) .with_url("shiba://localhost/index.html")? - .with_ipc_handler(move |_w, s| { - let m: MessageFromRenderer = serde_json::from_str(&s).unwrap(); - log::debug!("Message from WebView: {:?}", m); - if let Err(e) = ipc_proxy.send_event(UserEvent::IpcMessage(m)) { - log::error!("Could not send user event for message from WebView: {}", e); + .with_ipc_handler(move |msg| { + let msg: MessageFromRenderer = serde_json::from_str(&msg).unwrap(); + log::debug!("Message from WebView: {msg:?}"); + if let Err(err) = ipc_proxy.send_event(UserEvent::IpcMessage(msg)) { + log::error!("Could not send user event for message from WebView: {err}"); } }) - .with_file_drop_handler(move |_w, e| { - if let FileDropEvent::Dropped { paths, .. } = e { - log::debug!("Files were dropped (the first one will be opened): {:?}", paths); + .with_file_drop_handler(move |event| { + if let FileDropEvent::Dropped { paths, .. } = event { + log::debug!("Files were dropped (the first one will be opened): {paths:?}",); if let Some(path) = paths.into_iter().next() { - if let Err(e) = file_drop_proxy.send_event(UserEvent::FileDrop(path)) { - log::error!("Could not send user event for file drop: {}", e); + if let Err(err) = file_drop_proxy.send_event(UserEvent::FileDrop(path)) { + log::error!("Could not send user event for file drop: {err}"); } } } @@ -135,7 +135,7 @@ fn create_webview(window: Window, event_loop: &EventLoop, config: &Config) -> Re #[cfg(target_os = "windows")] { - use wry::webview::Theme; + use wry::Theme; builder = builder.with_browser_accelerator_keys(false); match config.window().theme { ThemeConfig::System => {} @@ -154,7 +154,7 @@ fn create_webview(window: Window, event_loop: &EventLoop, config: &Config) -> Re #[cfg(target_os = "macos")] { use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial}; - apply_vibrancy(webview.window(), NSVisualEffectMaterial::Sidebar, None, None)?; + apply_vibrancy(window, NSVisualEffectMaterial::Sidebar, None, None)?; } Ok(webview) @@ -162,6 +162,7 @@ fn create_webview(window: Window, event_loop: &EventLoop, config: &Config) -> Re pub struct WebViewRenderer { webview: WebView, + window: Window, zoom_level: ZoomLevel, always_on_top: bool, menu: Menu, @@ -203,7 +204,7 @@ impl WebViewRenderer { #[cfg(not(target_os = "macos"))] { - use wry::application::window::Icon; + use tao::window::Icon; let icon = Icon::from_rgba(ICON_RGBA.into(), 32, 32).unwrap(); builder = builder.with_window_icon(Some(icon)); } @@ -222,7 +223,7 @@ impl WebViewRenderer { menu.toggle(&window)?; } - let webview = create_webview(window, event_loop, config)?; + let webview = create_webview(&window, event_loop, config)?; log::debug!("WebView was created successfully"); let zoom_factor = zoom_level.factor(); @@ -237,7 +238,7 @@ impl WebViewRenderer { log::debug!("Opened DevTools for debugging"); } - Ok(WebViewRenderer { webview, zoom_level, always_on_top, menu }) + Ok(WebViewRenderer { webview, window, zoom_level, always_on_top, menu }) } } @@ -261,33 +262,32 @@ impl Renderer for WebViewRenderer { #[cfg(not(target_os = "macos"))] fn set_title(&self, title: &str) { log::debug!("Set window title: {}", title); - self.webview.window().set_title(title); + self.window.set_title(title); } #[cfg(target_os = "macos")] fn set_title(&self, _title: &str) {} // On macOS, the title bar is hidden fn window_state(&self) -> Option { - let PhysicalSize { width, height } = self.webview.inner_size(); // `self.webview.window().inner_size()` doesn't work - let w = self.webview.window(); - let PhysicalPosition { x, y } = match w.inner_position() { + let PhysicalSize { width, height } = self.window.inner_size(); + let PhysicalPosition { x, y } = match self.window.inner_position() { Ok(position) => position, Err(err) => { log::debug!("Could not get window position for window state: {}", err); return None; } }; - let fullscreen = w.fullscreen().is_some(); + let fullscreen = self.window.fullscreen().is_some(); let zoom_level = self.zoom_level; let always_on_top = self.always_on_top; Some(WindowState { width, height, x, y, fullscreen, zoom_level, always_on_top }) } fn theme(&self) -> RendererTheme { - window_theme(self.webview.window()) + window_theme(&self.window) } fn show(&self) { - self.webview.window().set_visible(true); + self.window.set_visible(true); } fn set_background_color(&self, rgba: (u8, u8, u8, u8)) -> Result<()> { @@ -310,7 +310,7 @@ impl Renderer for WebViewRenderer { fn set_always_on_top(&mut self, enabled: bool) { if self.always_on_top != enabled { - self.webview.window().set_always_on_top(enabled); + self.window.set_always_on_top(enabled); self.always_on_top = enabled; } } @@ -320,7 +320,7 @@ impl Renderer for WebViewRenderer { } fn drag_window(&self) -> Result<()> { - self.webview.window().drag_window().context("Could not start dragging the window") + self.window.drag_window().context("Could not start dragging the window") } fn window_appearance(&self) -> WindowAppearance { @@ -333,10 +333,10 @@ impl Renderer for WebViewRenderer { } fn show_menu_at(&self, position: Option<(f64, f64)>) { - self.menu.show_at(position, self.webview.window()); + self.menu.show_at(position, &self.window); } fn toggle_menu(&mut self) -> Result<()> { - self.menu.toggle(self.webview.window()) + self.menu.toggle(&self.window) } }