Skip to content

Commit

Permalink
check for termux before invoking android context
Browse files Browse the repository at this point in the history
  • Loading branch information
amodm committed Nov 8, 2022
1 parent d2a8ce6 commit 50b3cae
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/android.rs
Expand Up @@ -23,21 +23,20 @@ fn open_browser_default(url: &str, options: &BrowserOptions) -> Result<()> {
return Ok(());
}

// first we try to see if we're in a termux env, because if we are, then
// the android context may not have been initialized, and it'll panic
if try_for_termux(url, options).is_ok() {
return Ok(());
}

// Create a VM for executing Java calls
let ctx = ndk_context::android_context();
let vm = match unsafe { jni::JavaVM::from_raw(ctx.vm() as _) } {
Ok(x) => x,
Err(_) => {
// if we didn't get the vm instance, maybe we're running
// inside a termux, so try with that
return try_for_termux(url, options).map_err(|_| -> Error {
Error::new(
ErrorKind::NotFound,
"Expected to find JVM via ndk_context crate",
)
});
}
};
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm() as _) }.map_err(|_| -> Error {
Error::new(
ErrorKind::NotFound,
"Expected to find JVM via ndk_context crate",
)
})?;

let activity = unsafe { jni::objects::JObject::from_raw(ctx.context() as _) };
let env = vm.attach_current_thread().map_err(|_| -> Error {
Expand Down

0 comments on commit 50b3cae

Please sign in to comment.