From c3357127854b6a897ef601ce25b43ad452f0c2d5 Mon Sep 17 00:00:00 2001 From: c Date: Thu, 28 May 2026 13:31:33 +0200 Subject: [PATCH] wip: enforce ordering of android setup --- src/android/mod.rs | 2 +- src/lib.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/android/mod.rs b/src/android/mod.rs index 8c0beed76..02fef0dab 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -103,7 +103,7 @@ pub fn destroy_webview(activity_id: ActivityId, webview_id: &WebviewId) { /// /// This function must be run on the thread where the [`JNIEnv`] is registered and the looper is local, /// hence the requirement for a [`ThreadLooper`]. -pub unsafe fn android_setup( +pub(crate) unsafe fn android_setup( package: &str, mut env: JNIEnv, _looper: &ThreadLooper, diff --git a/src/lib.rs b/src/lib.rs index 1a8664ae1..cddcb8f79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -360,8 +360,6 @@ mod web_context; #[cfg(target_os = "android")] pub(crate) mod android; #[cfg(target_os = "android")] -pub use crate::android::android_setup; -#[cfg(target_os = "android")] pub mod prelude { pub use crate::android::{binding::*, dispatch, find_class, Context}; pub use tao_macros::{android_fn, generate_package_name}; @@ -1459,6 +1457,21 @@ impl<'a> WebViewBuilder<'a> { InnerWebView::new(window, self.attrs, self.platform_specific).map(|webview| WebView { webview }) } + #[cfg(target_os = "android")] + /// This function must be run on the thread where the [`JNIEnv`] is registered and the looper is local, + /// hence the requirement for a [`ThreadLooper`]. + pub unsafe fn build_android( + self, + window: &'a W, + package: &str, + env: jni::JNIEnv, + _looper: &ndk::looper::ThreadLooper, + activity: jni::objects::GlobalRef, + ) -> Result { + unsafe { android_setup(package, env, _looper, activity) }; + self.build(window) + } + /// Consume the builder and create the [`WebView`] as a child window inside the provided [`HasWindowHandle`]. /// /// ## Platform-specific