Ver Fonte

Update wry version to 0.50.1 (#3810)

Signed-off-by: SmileSky <mzdk100@foxmail.com>
SmileSky há 3 meses atrás
pai
commit
91a218039e

+ 1 - 1
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"

+ 1 - 2
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 = []
 

+ 4 - 4
packages/desktop/src/config.rs

@@ -70,12 +70,12 @@ impl LaunchConfig for Config {}
 
 pub(crate) type WryProtocol = (
     String,
-    Box<dyn Fn(HttpRequest<Vec<u8>>) -> HttpResponse<Cow<'static, [u8]>> + 'static>,
+    Box<dyn Fn(&str, HttpRequest<Vec<u8>>) -> HttpResponse<Cow<'static, [u8]>> + 'static>,
 );
 
 pub(crate) type AsyncWryProtocol = (
     String,
-    Box<dyn Fn(HttpRequest<Vec<u8>>, RequestAsyncResponder) + 'static>,
+    Box<dyn Fn(&str, HttpRequest<Vec<u8>>, RequestAsyncResponder) + 'static>,
 );
 
 impl Config {
@@ -188,7 +188,7 @@ impl Config {
     /// Set a custom protocol
     pub fn with_custom_protocol<F>(mut self, name: impl ToString, handler: F) -> Self
     where
-        F: Fn(HttpRequest<Vec<u8>>) -> HttpResponse<Cow<'static, [u8]>> + 'static,
+        F: Fn(&str, HttpRequest<Vec<u8>>) -> HttpResponse<Cow<'static, [u8]>> + '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<F>(mut self, name: impl ToString, handler: F) -> Self
     where
-        F: Fn(HttpRequest<Vec<u8>>, RequestAsyncResponder) + 'static,
+        F: Fn(&str, HttpRequest<Vec<u8>>, RequestAsyncResponder) + 'static,
     {
         self.asynchronous_protocols
             .push((name.to_string(), Box::new(handler)));

+ 41 - 43
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();

+ 1 - 2
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]