From 6f47b4e0253435366ae92e0882736cc7ee0e957d Mon Sep 17 00:00:00 2001 From: c Date: Tue, 24 Jun 2025 10:09:13 +0200 Subject: [PATCH 1/4] fix: warnings --- src/android/binding.rs | 36 ++++++++++++++++++------------------ src/android/main_pipe.rs | 4 ++-- src/android/mod.rs | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/android/binding.rs b/src/android/binding.rs index 8e7156834..9db80bd3a 100644 --- a/src/android/binding.rs +++ b/src/android/binding.rs @@ -159,9 +159,9 @@ fn handle_request( let final_request = match request_builder.body(Vec::new()) { Ok(req) => req, - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to build response: {}", e); + tracing::warn!("Failed to build response: {_e}"); return Ok(*JObject::null()); } }; @@ -190,9 +190,9 @@ fn handle_request( } else { None }; - if let Some(err) = status_err { + if let Some(_err) = status_err { #[cfg(feature = "tracing")] - tracing::warn!("{}", err); + tracing::warn!("{_err}"); return Ok(*JObject::null()); } @@ -280,9 +280,9 @@ pub unsafe fn handleRequest( is_document_start_script_enabled, ) { Ok(response) => response, - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to handle request: {}", e); + tracing::warn!("Failed to handle request: {_e}"); JObject::null().as_raw() } } @@ -304,9 +304,9 @@ pub unsafe fn shouldOverride(mut env: JNIEnv, _: JClass, url: JString) -> jboole .map(|f| !(f.handler)(url)) .unwrap_or(false) } - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e); + tracing::warn!("Failed to parse JString: {_e}"); false } } @@ -326,9 +326,9 @@ pub unsafe fn onEval(mut env: JNIEnv, _: JClass, id: jint, result: JString) { cb(result.into()); } } - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e); + tracing::warn!("Failed to parse JString: {_e}"); } } } @@ -345,9 +345,9 @@ pub unsafe fn ipc(mut env: JNIEnv, _: JClass, url: JString, body: JString) { (ipc.handler)(Request::builder().uri(url).body(body).unwrap()) } } - (Err(e), _) | (_, Err(e)) => { + (Err(_e), _) | (_, Err(_e)) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e) + tracing::warn!("Failed to parse JString: {_e}") } } } @@ -361,9 +361,9 @@ pub unsafe fn handleReceivedTitle(mut env: JNIEnv, _: JClass, _webview: JObject, (title_handler.handler)(title) } } - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e) + tracing::warn!("Failed to parse JString: {_e}") } } } @@ -391,9 +391,9 @@ pub unsafe fn onPageLoading(mut env: JNIEnv, _: JClass, url: JString) { (on_load.handler)(PageLoadEvent::Started, url) } } - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e) + tracing::warn!("Failed to parse JString: {_e}") } } } @@ -407,9 +407,9 @@ pub unsafe fn onPageLoaded(mut env: JNIEnv, _: JClass, url: JString) { (on_load.handler)(PageLoadEvent::Finished, url) } } - Err(e) => { + Err(_e) => { #[cfg(feature = "tracing")] - tracing::warn!("Failed to parse JString: {}", e) + tracing::warn!("Failed to parse JString: {_e}") } } } diff --git a/src/android/main_pipe.rs b/src/android/main_pipe.rs index 5b81048ef..662932ca4 100644 --- a/src/android/main_pipe.rs +++ b/src/android/main_pipe.rs @@ -226,13 +226,13 @@ impl<'a> MainPipe<'a> { )?; if let Some(on_webview_created) = on_webview_created { - if let Err(e) = on_webview_created(super::Context { + if let Err(_e) = on_webview_created(super::Context { env: &mut self.env, activity, webview: &webview, }) { #[cfg(feature = "tracing")] - tracing::warn!("failed to run webview created hook: {e}"); + tracing::warn!("failed to run webview created hook: {_e}"); } } diff --git a/src/android/mod.rs b/src/android/mod.rs index 6f6805e0e..596082256 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -347,7 +347,7 @@ impl InnerWebView { Ok(()) } - pub fn id(&self) -> crate::WebViewId { + pub fn id(&self) -> crate::WebViewId<'_> { &self.id } From 55fa1709c7e17ba4c262ad1660e274f7c47e85e6 Mon Sep 17 00:00:00 2001 From: c Date: Tue, 24 Jun 2025 10:10:00 +0200 Subject: [PATCH 2/4] fix: remove sketchy Send, Sync impls StaticValue is simply a wrapper around Mutex. For Mutex to be Send or Sync the stdlib requires T: Send. This bound is missing on the Send and Sync impl of StaticValue. The Send impl is not even needed, remove it. --- src/android/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/android/mod.rs b/src/android/mod.rs index 596082256..fcaa1a05e 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -46,7 +46,6 @@ pub struct Context<'a, 'b> { pub(crate) struct StaticValue(Mutex); -unsafe impl Send for StaticValue {} unsafe impl Sync for StaticValue {} impl std::ops::Deref for StaticValue { @@ -69,9 +68,7 @@ macro_rules! define_static_handlers { $($fields,)* } } - } - unsafe impl Send for $type_name {} - unsafe impl Sync for $type_name {})* + })* }; } From c4962a99d23dc0d208c8f22e29bc51c0d43a185c Mon Sep 17 00:00:00 2001 From: c Date: Tue, 24 Jun 2025 10:56:49 +0200 Subject: [PATCH 3/4] fix: clippy --- src/android/mod.rs | 8 ++++---- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/android/mod.rs b/src/android/mod.rs index fcaa1a05e..f3f649253 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -113,7 +113,7 @@ pub unsafe fn android_setup( let webchrome_client = env .new_object( &rust_webchrome_client_class, - &format!("(L{}/WryActivity;)V", PACKAGE.get().unwrap()), + format!("(L{}/WryActivity;)V", PACKAGE.get().unwrap()), &[activity.as_obj().into()], ) .unwrap(); @@ -217,12 +217,12 @@ impl InnerWebView { move |webview_id: &str, mut request, is_document_start_script_enabled| { let uri = request.uri().to_string(); if let Some((custom_protocol_uri, custom_protocol_closure)) = custom_protocols.iter().find(|(name, _)| { - uri.starts_with(&format!("{scheme}://{}.", name)) + uri.starts_with(&format!("{scheme}://{name}.")) }) { let uri_res = uri .replace( - &format!("{scheme}://{}.", custom_protocol_uri), - &format!("{}://", custom_protocol_uri), + &format!("{scheme}://{custom_protocol_uri}."), + &format!("{custom_protocol_uri}://"), ) .parse(); diff --git a/src/lib.rs b/src/lib.rs index 6a9d8dc21..1628ef7a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1840,7 +1840,7 @@ impl WebViewBuilderExtAndroid for WebViewBuilder<'_> { }), ); self.platform_specific.with_asset_loader = true; - self.platform_specific.asset_loader_domain = Some(format!("{}.assets", protocol)); + self.platform_specific.asset_loader_domain = Some(format!("{protocol}.assets")); self } From f5742262e13f4099a265dff39692a18a68cb4838 Mon Sep 17 00:00:00 2001 From: c Date: Sat, 16 Aug 2025 17:07:16 +0200 Subject: [PATCH 4/4] refactor: make more private --- src/android/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/android/mod.rs b/src/android/mod.rs index f3f649253..55b2b751a 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -44,7 +44,7 @@ pub struct Context<'a, 'b> { pub webview: &'a JObject<'b>, } -pub(crate) struct StaticValue(Mutex); +struct StaticValue(Mutex); unsafe impl Sync for StaticValue {} @@ -58,12 +58,12 @@ impl std::ops::Deref for StaticValue { macro_rules! define_static_handlers { ($($var:ident = $type_name:ident { $($fields:ident:$types:ty),+ $(,)? });+ $(;)?) => { - $(pub static $var: StaticValue> = StaticValue(Mutex::new(None)); - pub struct $type_name { + $(static $var: StaticValue> = StaticValue(Mutex::new(None)); + struct $type_name { $($fields: $types,)* } impl $type_name { - pub fn new($($fields: $types,)*) -> Self { + fn new($($fields: $types,)*) -> Self { Self { $($fields,)* } @@ -80,15 +80,15 @@ define_static_handlers! { ON_LOAD_HANDLER = UnsafeOnPageLoadHandler { handler: Box }; } -pub static WITH_ASSET_LOADER: StaticValue> = StaticValue(Mutex::new(None)); -pub static ASSET_LOADER_DOMAIN: StaticValue> = StaticValue(Mutex::new(None)); +static WITH_ASSET_LOADER: Mutex> = Mutex::new(None); +static ASSET_LOADER_DOMAIN: Mutex> = Mutex::new(None); -pub(crate) static PACKAGE: OnceCell = OnceCell::new(); +static PACKAGE: OnceCell = OnceCell::new(); type EvalCallback = Box; -pub static EVAL_ID_GENERATOR: Counter = Counter::new(); -pub static EVAL_CALLBACKS: OnceCell>> = OnceCell::new(); +static EVAL_ID_GENERATOR: Counter = Counter::new(); +static EVAL_CALLBACKS: OnceCell>> = OnceCell::new(); /// Sets up the necessary logic for wry to be able to create the webviews later. ///