diff --git a/Cargo.toml b/Cargo.toml index 61a16d9ce..08e42248f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -248,7 +248,7 @@ itertools = "0.14.0" macro-string = "0.1.3" # desktop -wry = { version = "0.45.0", default-features = false } +wry = { version = "0.50.1", default-features = false } tao = { version = "0.30.8", features = ["rwh_05"] } webbrowser = "1.0.1" infer = "0.16.0" diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index 6af3b1d42..97bea3e5a 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -102,11 +102,10 @@ objc = "0.2.7" lazy-js-bundle = { workspace = true } [features] -default = ["tokio_runtime", "exception", "transparent", "devtools"] +default = ["tokio_runtime", "transparent", "devtools"] tokio_runtime = ["dep:tokio"] fullscreen = ["wry/fullscreen"] devtools = ["wry/devtools", "dep:dioxus-devtools", "dioxus-signals"] -exception = ["wry/objc-exception"] transparent = ["wry/transparent"] gnu = [] diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index 9a89b4f05..ade3ac060 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -70,12 +70,12 @@ impl LaunchConfig for Config {} pub(crate) type WryProtocol = ( String, - Box>) -> HttpResponse> + 'static>, + Box>) -> HttpResponse> + 'static>, ); pub(crate) type AsyncWryProtocol = ( String, - Box>, RequestAsyncResponder) + 'static>, + Box>, RequestAsyncResponder) + 'static>, ); impl Config { @@ -188,7 +188,7 @@ impl Config { /// Set a custom protocol pub fn with_custom_protocol(mut self, name: impl ToString, handler: F) -> Self where - F: Fn(HttpRequest>) -> HttpResponse> + 'static, + F: Fn(&str, HttpRequest>) -> HttpResponse> + 'static, { self.protocols.push((name.to_string(), Box::new(handler))); self @@ -222,7 +222,7 @@ impl Config { /// See [`wry`](wry::WebViewBuilder::with_asynchronous_custom_protocol) for more details on implementation pub fn with_asynchronous_custom_protocol(mut self, name: impl ToString, handler: F) -> Self where - F: Fn(HttpRequest>, RequestAsyncResponder) + 'static, + F: Fn(&str, HttpRequest>, RequestAsyncResponder) + 'static, { self.asynchronous_protocols .push((name.to_string(), Box::new(handler))); diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 05ff7c0ad..ca025db7a 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -235,7 +235,7 @@ impl WebviewInstance { asset_handlers, edits ]; - move |request, responder: RequestAsyncResponder| { + move |_id: wry::WebViewId, request, responder: RequestAsyncResponder| { protocol::desktop_handler( request, asset_handlers.clone(), @@ -303,39 +303,7 @@ impl WebviewInstance { } }; - #[cfg(any( - target_os = "windows", - target_os = "macos", - target_os = "ios", - target_os = "android" - ))] - let mut webview = if cfg.as_child_window { - WebViewBuilder::new_as_child(&window) - } else { - WebViewBuilder::new(&window) - }; - - #[cfg(not(any( - target_os = "windows", - target_os = "macos", - target_os = "ios", - target_os = "android" - )))] - let mut webview = { - use tao::platform::unix::WindowExtUnix; - use wry::WebViewBuilderExtUnix; - let vbox = window.default_vbox().unwrap(); - WebViewBuilder::new_gtk(vbox) - }; - - // Disable the webview default shortcuts to disable the reload shortcut - #[cfg(target_os = "windows")] - { - use wry::WebViewBuilderExtWindows; - webview = webview.with_browser_accelerator_keys(false); - } - - webview = webview + let mut wv_builder = WebViewBuilder::with_web_context(&mut web_context) .with_bounds(wry::Rect { position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)), size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new( @@ -358,23 +326,29 @@ impl WebviewInstance { false } }) // prevent all navigations - .with_asynchronous_custom_protocol(String::from("dioxus"), request_handler) - .with_web_context(&mut web_context); + .with_asynchronous_custom_protocol(String::from("dioxus"), request_handler); + + // Disable the webview default shortcuts to disable the reload shortcut + #[cfg(target_os = "windows")] + { + use wry::WebViewBuilderExtWindows; + wv_builder = wv_builder.with_browser_accelerator_keys(false); + } if !cfg.disable_file_drop_handler { - webview = webview.with_drag_drop_handler(file_drop_handler); + wv_builder = wv_builder.with_drag_drop_handler(file_drop_handler); } if let Some(color) = cfg.background_color { - webview = webview.with_background_color(color); + wv_builder = wv_builder.with_background_color(color); } for (name, handler) in cfg.protocols.drain(..) { - webview = webview.with_custom_protocol(name, handler); + wv_builder = wv_builder.with_custom_protocol(name, handler); } for (name, handler) in cfg.asynchronous_protocols.drain(..) { - webview = webview.with_asynchronous_custom_protocol(name, handler); + wv_builder = wv_builder.with_asynchronous_custom_protocol(name, handler); } const INITIALIZATION_SCRIPT: &str = r#" @@ -391,13 +365,37 @@ impl WebviewInstance { if cfg.disable_context_menu { // in release mode, we don't want to show the dev tool or reload menus - webview = webview.with_initialization_script(INITIALIZATION_SCRIPT) + wv_builder = wv_builder.with_initialization_script(INITIALIZATION_SCRIPT) } else { // in debug, we are okay with the reload menu showing and dev tool - webview = webview.with_devtools(true); + wv_builder = wv_builder.with_devtools(true); } - let webview = webview.build().unwrap(); + #[cfg(any( + target_os = "windows", + target_os = "macos", + target_os = "ios", + target_os = "android" + ))] + let webview = if cfg.as_child_window { + wv_builder.build_as_child(&window) + } else { + wv_builder.build(&window) + } + .unwrap(); + + #[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_os = "ios", + target_os = "android" + )))] + let webview = { + use tao::platform::unix::WindowExtUnix; + use wry::WebViewBuilderExtUnix; + let vbox = window.default_vbox().unwrap(); + wv_builder.build_gtk(vbox).unwrap() + }; let menu = if cfg!(not(any(target_os = "android", target_os = "ios"))) { let menu_option = cfg.menu.into(); diff --git a/packages/mobile/Cargo.toml b/packages/mobile/Cargo.toml index 3fc666756..473653972 100644 --- a/packages/mobile/Cargo.toml +++ b/packages/mobile/Cargo.toml @@ -20,14 +20,13 @@ once_cell.workspace = true jni = "0.21.1" [features] -default = ["jnibindings", "tokio_runtime", "devtools", "exception"] +default = ["jnibindings", "tokio_runtime", "devtools"] jnibindings = [] tokio_runtime = ["dioxus-desktop/tokio_runtime"] fullscreen = ["dioxus-desktop/fullscreen"] transparent = ["dioxus-desktop/transparent"] devtools = ["dioxus-desktop/devtools"] gnu = ["dioxus-desktop/gnu"] -exception = ["dioxus-desktop/exception"] [lib]