Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): support private plugin callbacks and commands #6863

Merged
merged 1 commit into from May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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