Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/android/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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
}
}
Expand All @@ -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}");
}
}
}
Expand All @@ -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}")
}
}
}
Expand All @@ -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}")
}
}
}
Expand Down Expand Up @@ -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}")
}
}
}
Expand All @@ -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}")
}
}
}
4 changes: 2 additions & 2 deletions src/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}

Expand Down
33 changes: 15 additions & 18 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ pub struct Context<'a, 'b> {
pub webview: &'a JObject<'b>,
}

pub(crate) struct StaticValue<T>(Mutex<T>);
struct StaticValue<T>(Mutex<T>);

unsafe impl<T> Send for StaticValue<T> {}
unsafe impl<T> Sync for StaticValue<T> {}

impl<T> std::ops::Deref for StaticValue<T> {
Expand All @@ -59,19 +58,17 @@ impl<T> std::ops::Deref for StaticValue<T> {

macro_rules! define_static_handlers {
($($var:ident = $type_name:ident { $($fields:ident:$types:ty),+ $(,)? });+ $(;)?) => {
$(pub static $var: StaticValue<Option<$type_name>> = StaticValue(Mutex::new(None));
pub struct $type_name {
$(static $var: StaticValue<Option<$type_name>> = 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,)*
}
}
}
unsafe impl Send for $type_name {}
unsafe impl Sync for $type_name {})*
})*
};
}

Expand All @@ -83,15 +80,15 @@ define_static_handlers! {
ON_LOAD_HANDLER = UnsafeOnPageLoadHandler { handler: Box<dyn Fn(PageLoadEvent, String)> };
}

pub static WITH_ASSET_LOADER: StaticValue<Option<bool>> = StaticValue(Mutex::new(None));
pub static ASSET_LOADER_DOMAIN: StaticValue<Option<String>> = StaticValue(Mutex::new(None));
static WITH_ASSET_LOADER: Mutex<Option<bool>> = Mutex::new(None);
static ASSET_LOADER_DOMAIN: Mutex<Option<String>> = Mutex::new(None);

pub(crate) static PACKAGE: OnceCell<String> = OnceCell::new();
static PACKAGE: OnceCell<String> = OnceCell::new();

type EvalCallback = Box<dyn Fn(String) + Send + 'static>;

pub static EVAL_ID_GENERATOR: Counter = Counter::new();
pub static EVAL_CALLBACKS: OnceCell<Mutex<HashMap<i32, EvalCallback>>> = OnceCell::new();
static EVAL_ID_GENERATOR: Counter = Counter::new();
static EVAL_CALLBACKS: OnceCell<Mutex<HashMap<i32, EvalCallback>>> = OnceCell::new();

/// Sets up the necessary logic for wry to be able to create the webviews later.
///
Expand All @@ -116,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();
Expand Down Expand Up @@ -220,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();

Expand Down Expand Up @@ -347,7 +344,7 @@ impl InnerWebView {
Ok(())
}

pub fn id(&self) -> crate::WebViewId {
pub fn id(&self) -> crate::WebViewId<'_> {
&self.id
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down