ReviewOS

also looking at this

craft-native/craft

feat(android): the reply channel, so async actions become reachable

#152
Merged chris wants to merge feat/android-reply-channel into main
5 files +464 -0
packages/android/templates/CraftBridge.kt.templatemodified+21-0
Changes to packages/android/templates/CraftBridge.kt.template
@@ -167,6 +167,11 @@ class CraftBridge(
167167 }
168168
169169 fun injectBridge() {
170 // Before the script, so a native callback arriving while the page is
171 // still loading has somewhere to go rather than being counted as
172 // dropped.
173 installNativeDeliverer()
174
170175 val script = """
171176 window.craft = {
172177 platform: 'android',
@@ -3898,6 +3903,22 @@ class CraftBridge(
38983903
38993904 // ==================== Helpers ====================
39003905
3906 /**
3907 * Give Zig a way to reach the page.
3908 *
3909 * The lambda is this class's own `runOnUiThread`/`evaluateJavascript`
3910 * pair, which is what `sendEvent` below already does — so Zig and Kotlin
3911 * deliver through exactly one implementation rather than two that have to
3912 * agree about threading.
3913 */
3914 private fun installNativeDeliverer() {
3915 CraftNative.setDeliverer { script ->
3916 activity.runOnUiThread {
3917 webView.evaluateJavascript(script, null)
3918 }
3919 }
3920 }
3921
39013922 private fun sendEvent(event: String, data: Map<String, Any>) {
39023923 val json = JSONObject(data).toString()
39033924 activity.runOnUiThread {