@tokamakdev/platform-android-arm64 0.1.1-beta.116 → 0.1.1-beta.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,25 +18,22 @@ class TokamakBinding(payload: ByteArray, private val resources: TokamakResources
|
|
|
18
18
|
val unavailable get() = TokamakPluginError.notSupported("The API is unavailable on this API level")
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
private val request =
|
|
22
|
-
|
|
23
|
-
}
|
|
21
|
+
private val request = decodePluginValue(payload) as? JSONObject
|
|
22
|
+
?: throw TokamakPluginError.typeError("A binding request is an object")
|
|
24
23
|
|
|
25
24
|
/** Argument [index] as JSON. */
|
|
26
|
-
operator fun get(index: Int): Any? = request.
|
|
25
|
+
operator fun get(index: Int): Any? = request.optJSONArray("arguments")?.opt(index) ?: JSONObject.NULL
|
|
27
26
|
|
|
28
27
|
/** The object the call is made on. */
|
|
29
|
-
fun <T : Any> target(type: Class<T>): T = obj(request.
|
|
28
|
+
fun <T : Any> target(type: Class<T>): T = obj(request.opt("target"), type)
|
|
30
29
|
|
|
31
30
|
/** The handlers an implementation calls. */
|
|
32
|
-
val methods: Set<String>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
31
|
+
val methods: Set<String> by lazy {
|
|
32
|
+
val methods = request.optJSONArray("methods") ?: return@lazy emptySet()
|
|
33
|
+
(0 until methods.length()).map(methods::getString).toSet()
|
|
34
|
+
}
|
|
37
35
|
|
|
38
|
-
private val scope: String
|
|
39
|
-
get() = request.getOrNull()?.optString("scope").orEmpty()
|
|
36
|
+
private val scope: String get() = request.optString("scope")
|
|
40
37
|
|
|
41
38
|
fun boolean(value: Any?): Boolean = value as? Boolean ?: throw mismatch(value, "boolean")
|
|
42
39
|
|
|
@@ -143,12 +140,6 @@ class TokamakBinding(payload: ByteArray, private val resources: TokamakResources
|
|
|
143
140
|
return true
|
|
144
141
|
}
|
|
145
142
|
|
|
146
|
-
/** Rejects the member the plugin does not bind. */
|
|
147
|
-
fun unsupported(member: String): (() -> Unit)? {
|
|
148
|
-
reply(TokamakPluginResult.encoded(Result.failure(TokamakPluginError.notSupported("$member is not supported")), true))
|
|
149
|
-
return null
|
|
150
|
-
}
|
|
151
|
-
|
|
152
143
|
private fun send(value: Any?) {
|
|
153
144
|
reply(TokamakPluginResult.encoded(runCatching { encodePluginValue(value) }, false))
|
|
154
145
|
}
|
|
@@ -206,9 +206,11 @@ interface TokamakHost {
|
|
|
206
206
|
*/
|
|
207
207
|
fun emitBytes(name: String, payload: ByteArray, timeoutMillis: Long): ByteArray
|
|
208
208
|
|
|
209
|
-
/** [emitBytes] with
|
|
210
|
-
fun emit(name: String, event:
|
|
211
|
-
emitBytes(name, event
|
|
209
|
+
/** [emitBytes] with [event] encoded as JSON, returning their reply decoded from JSON, or null when none replied. */
|
|
210
|
+
fun emit(name: String, event: Any?, timeoutMillis: Long): Any? {
|
|
211
|
+
val reply = emitBytes(name, encodePluginValue(event), timeoutMillis)
|
|
212
|
+
return if (reply.isEmpty()) null else decodePluginValue(reply).takeUnless { it == JSONObject.NULL }
|
|
213
|
+
}
|
|
212
214
|
|
|
213
215
|
/**
|
|
214
216
|
* What the app serves at [path], as its WebView would load it: a file the app ships or the
|