also looking at this
feat(android): the reply channel, so async actions become reachable
#152
5 files
+464
-0
| @@ -167,6 +167,11 @@ class CraftBridge( | ||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | 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 | ||
| 170 | 175 | val script = """ |
| 171 | 176 | window.craft = { |
| 172 | 177 | platform: 'android', |
| @@ -3898,6 +3903,22 @@ class CraftBridge( | ||
| 3898 | 3903 | |
| 3899 | 3904 | // ==================== Helpers ==================== |
| 3900 | 3905 | |
| 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 | ||
| 3901 | 3922 | private fun sendEvent(event: String, data: Map<String, Any>) { |
| 3902 | 3923 | val json = JSONObject(data).toString() |
| 3903 | 3924 | activity.runOnUiThread { |