Skip to content

Commit

Permalink
feat(android): change WebViewMessage::Eval to run specific script (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 13, 2022
1 parent 3d66ad0 commit 903c7e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/android-eval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Changed `WebViewMessage::Eval` to evaluate an specific script.
13 changes: 13 additions & 0 deletions src/platform_impl/android/ndk_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ impl MainPipe<'_> {
}
}
}
WebViewMessage::Eval(script) => {
if let Some(webview) = &self.webview {
let s = env.new_string(script)?;
env.call_method(
webview.as_obj(),
"evaluateJavascript",
"(Ljava/lang/String;Landroid/webkit/ValueCallback;)V",
&[s.into(), JObject::null().into()],
)?;
}
}
}
}
Ok(())
Expand All @@ -210,6 +221,8 @@ impl MainPipe<'_> {
pub enum WebViewMessage {
CreateWebView(String, Vec<String>, bool),
RunInitializationScripts,
// evaluate a single script
Eval(String),
}

pub static IPC: OnceCell<UnsafeIpc> = OnceCell::new();
Expand Down

0 comments on commit 903c7e7

Please sign in to comment.