Skip to content

Commit

Permalink
feat(android): support private plugin callbacks and commands (#6863)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 5, 2023
1 parent 73c803a commit 256c30c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/android-enhance-method-parse.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Enhance parsing of annotated Android plugin methods to support private functions.
Expand Up @@ -12,10 +12,12 @@ import androidx.core.app.ActivityCompat
import app.tauri.PermissionHelper
import app.tauri.PermissionState
import app.tauri.annotation.ActivityCallback
import app.tauri.annotation.PermissionCallback
import app.tauri.annotation.Command
import app.tauri.annotation.PermissionCallback
import app.tauri.annotation.TauriPlugin
import java.lang.reflect.Method
import java.util.Arrays


class PluginHandle(private val manager: PluginManager, val name: String, val instance: Plugin, val config: JSObject) {
private val commands: HashMap<String, CommandData> = HashMap()
Expand Down Expand Up @@ -130,7 +132,13 @@ class PluginHandle(private val manager: PluginManager, val name: String, val ins
}

private fun indexMethods() {
val methods: Array<Method> = instance.javaClass.methods
val methods = mutableListOf<Method>()
var pluginCursor: Class<*> = instance.javaClass
while (pluginCursor.name != Any::class.java.name) {
methods.addAll(listOf(*pluginCursor.declaredMethods))
pluginCursor = pluginCursor.superclass
}

for (method in methods) {
if (method.isAnnotationPresent(Command::class.java)) {
val command = method.getAnnotation(Command::class.java) ?: continue
Expand Down
Expand Up @@ -121,7 +121,7 @@ class PluginManager(val activity: AppCompatActivity) {
plugins[pluginId]?.invoke(invoke)
}
} catch (e: Exception) {
invoke.reject(e.message)
invoke.reject(if (e.message?.isEmpty() != false) { e.toString() } else { e.message })
}
}

Expand Down

0 comments on commit 256c30c

Please sign in to comment.