From a563a6404b3f966136ff6dacb0fe3ce681581ce4 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 14 Oct 2024 14:30:59 +0300 Subject: [PATCH] chore: update wry to 0.46 (#402) --- templates/apps/wry/Cargo.toml.hbs | 4 +- templates/apps/wry/src/lib.rs.hbs | 100 +++++++++--------------------- 2 files changed, 30 insertions(+), 74 deletions(-) diff --git a/templates/apps/wry/Cargo.toml.hbs b/templates/apps/wry/Cargo.toml.hbs index 30758dd0..d5fa0274 100644 --- a/templates/apps/wry/Cargo.toml.hbs +++ b/templates/apps/wry/Cargo.toml.hbs @@ -35,8 +35,8 @@ frameworks = [ "WebKit" ] [dependencies] anyhow = "1.0" log = "0.4" -wry = "0.37" -tao = "0.26" +wry = "0.46" +tao = "0.30" [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.13" diff --git a/templates/apps/wry/src/lib.rs.hbs b/templates/apps/wry/src/lib.rs.hbs index 89a3c89a..dcbdcfd5 100644 --- a/templates/apps/wry/src/lib.rs.hbs +++ b/templates/apps/wry/src/lib.rs.hbs @@ -83,6 +83,30 @@ fn build_webview(event_loop: &EventLoopWindowTarget<()>) -> anyhow::Result + + Hello Wry!! + + "# + .as_bytes() + .into(), + ) + .unwrap_or_default() + }); #[cfg(any( target_os = "windows", @@ -90,87 +114,19 @@ fn build_webview(event_loop: &EventLoopWindowTarget<()>) -> anyhow::Result r.map(Into::into), - Err(e) => http::Response::builder() - .header(http::header::CONTENT_TYPE, "text/plain") - .status(500) - .body(e.to_string().as_bytes().to_vec()) - .unwrap() - .map(Into::into), - } - }) - .build()?; Ok(webview) -} - -fn process_custom_protcol( - _request: http::Request>, -) -> anyhow::Result>> { - #[cfg(not(target_os = "android"))] - { - use std::fs::{canonicalize, read}; - use wry::http::header::CONTENT_TYPE; - - // Remove url scheme - let path = _request.uri().path(); - - #[cfg(not(target_os = "ios"))] - let content = read(canonicalize(&path[1..])?)?; - - #[cfg(target_os = "ios")] - let content = { - let path = core_foundation::bundle::CFBundle::main_bundle() - .resources_path() - .unwrap() - .join(&path); - read(canonicalize(&path)?)? - }; - - // Return asset contents and mime types based on file extentions - // If you don't want to do this manually, there are some crates for you. - // Such as `infer` and `mime_guess`. - let (data, meta) = if path.ends_with(".html") { - (content, "text/html") - } else if path.ends_with(".js") { - (content, "text/javascript") - } else if path.ends_with(".png") { - (content, "image/png") - } else { - unimplemented!(); - }; - - Ok(http::Response::builder() - .header(CONTENT_TYPE, meta) - .body(data.into())?) - } - - #[cfg(target_os = "android")] - { - Ok(http::Response::builder().body(Vec::new().into())?) - } -} +} \ No newline at end of file