mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-29 05:51:59 +03:00
refactor(android): rename PluginMethod to Command
This commit is contained in:
parent
22c09871c3
commit
a6fea4644e
2
core/tauri/mobile/android/proguard-rules.pro
vendored
2
core/tauri/mobile/android/proguard-rules.pro
vendored
@ -7,7 +7,7 @@
|
||||
}
|
||||
|
||||
-keep @app.tauri.annotation.TauriPlugin public class * {
|
||||
@app.tauri.annotation.PluginMethod public <methods>;
|
||||
@app.tauri.annotation.Command public <methods>;
|
||||
@app.tauri.annotation.PermissionCallback <methods>;
|
||||
@app.tauri.annotation.ActivityCallback <methods>;
|
||||
@app.tauri.annotation.Permission <methods>;
|
||||
|
@ -5,4 +5,4 @@
|
||||
package app.tauri.annotation
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class PluginMethod
|
||||
annotation class Command
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
package app.tauri.plugin
|
||||
|
||||
internal class InvalidPluginMethodException : Exception {
|
||||
internal class InvalidCommandException : Exception {
|
||||
constructor(s: String?) : super(s) {}
|
||||
constructor(t: Throwable?) : super(t) {}
|
||||
constructor(s: String?, t: Throwable?) : super(s, t) {}
|
||||
|
@ -16,7 +16,7 @@ import app.tauri.PermissionHelper
|
||||
import app.tauri.PermissionState
|
||||
import app.tauri.annotation.ActivityCallback
|
||||
import app.tauri.annotation.PermissionCallback
|
||||
import app.tauri.annotation.PluginMethod
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import org.json.JSONException
|
||||
import java.util.*
|
||||
@ -72,7 +72,7 @@ abstract class Plugin(private val activity: Activity) {
|
||||
* declared on the plugin. This plugin call responds with a mapping of permissions to
|
||||
* the associated granted status.
|
||||
*/
|
||||
@PluginMethod
|
||||
@Command
|
||||
@PermissionCallback
|
||||
fun checkPermissions(invoke: Invoke) {
|
||||
val permissionsResult: Map<String, PermissionState?> = getPermissionStates()
|
||||
@ -97,7 +97,7 @@ abstract class Plugin(private val activity: Activity) {
|
||||
*
|
||||
* @param invoke
|
||||
*/
|
||||
@PluginMethod
|
||||
@Command
|
||||
open fun requestPermissions(invoke: Invoke) {
|
||||
val annotation = handle?.annotation
|
||||
if (annotation != null) {
|
||||
|
@ -13,12 +13,12 @@ import app.tauri.PermissionHelper
|
||||
import app.tauri.PermissionState
|
||||
import app.tauri.annotation.ActivityCallback
|
||||
import app.tauri.annotation.PermissionCallback
|
||||
import app.tauri.annotation.PluginMethod
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class PluginHandle(private val manager: PluginManager, val name: String, private val instance: Plugin) {
|
||||
private val pluginMethods: HashMap<String, PluginMethodData> = HashMap()
|
||||
private val commands: HashMap<String, CommandData> = HashMap()
|
||||
private val permissionCallbackMethods: HashMap<String, Method> = HashMap()
|
||||
private val startActivityCallbackMethods: HashMap<String, Method> = HashMap()
|
||||
var annotation: TauriPlugin?
|
||||
@ -120,22 +120,22 @@ class PluginHandle(private val manager: PluginManager, val name: String, private
|
||||
}
|
||||
|
||||
@Throws(
|
||||
InvalidPluginMethodException::class,
|
||||
InvalidCommandException::class,
|
||||
IllegalAccessException::class
|
||||
)
|
||||
fun invoke(invoke: Invoke) {
|
||||
val methodMeta = pluginMethods[invoke.command]
|
||||
?: throw InvalidPluginMethodException("No command " + invoke.command + " found for plugin " + instance.javaClass.name)
|
||||
val methodMeta = commands[invoke.command]
|
||||
?: throw InvalidCommandException("No command " + invoke.command + " found for plugin " + instance.javaClass.name)
|
||||
methodMeta.method.invoke(instance, invoke)
|
||||
}
|
||||
|
||||
private fun indexMethods() {
|
||||
val methods: Array<Method> = instance.javaClass.methods
|
||||
for (method in methods) {
|
||||
if (method.isAnnotationPresent(PluginMethod::class.java)) {
|
||||
val pluginMethod = method.getAnnotation(PluginMethod::class.java) ?: continue
|
||||
val methodMeta = PluginMethodData(method, pluginMethod)
|
||||
pluginMethods[method.name] = methodMeta
|
||||
if (method.isAnnotationPresent(Command::class.java)) {
|
||||
val command = method.getAnnotation(Command::class.java) ?: continue
|
||||
val methodMeta = CommandData(method, command)
|
||||
commands[method.name] = methodMeta
|
||||
} else if (method.isAnnotationPresent(ActivityCallback::class.java)) {
|
||||
startActivityCallbackMethods[method.name] = method
|
||||
} else if (method.isAnnotationPresent(PermissionCallback::class.java)) {
|
||||
|
@ -91,7 +91,7 @@ class PluginManager(val activity: AppCompatActivity) {
|
||||
}
|
||||
|
||||
@JniMethod
|
||||
fun runPluginMethod(id: Int, pluginId: String, command: String, data: JSObject) {
|
||||
fun runCommand(id: Int, pluginId: String, command: String, data: JSObject) {
|
||||
val invoke = Invoke(id.toLong(), command, { successResult, errorResult ->
|
||||
handlePluginResponse(id, successResult?.toString(), errorResult?.toString())
|
||||
}, data)
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
package app.tauri.plugin
|
||||
|
||||
import app.tauri.annotation.PluginMethod
|
||||
import app.tauri.annotation.Command
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class PluginMethodData(
|
||||
val method: Method, methodDecorator: PluginMethod
|
||||
class CommandData(
|
||||
val method: Method, methodDecorator: Command
|
||||
) {
|
||||
|
||||
// The name of the method
|
||||
|
@ -121,7 +121,7 @@ func postIpcMessage(webview: WKWebView, name: SRString, command: SRString, data:
|
||||
}
|
||||
|
||||
@_cdecl("run_plugin_method")
|
||||
func runPluginMethod(
|
||||
func runCommand(
|
||||
id: Int,
|
||||
name: SRString,
|
||||
command: SRString,
|
||||
|
@ -324,7 +324,7 @@ impl<R: Runtime> PluginHandle<R> {
|
||||
|
||||
env.call_method(
|
||||
plugin_manager,
|
||||
"runPluginMethod",
|
||||
"runCommand",
|
||||
"(ILjava/lang/String;Ljava/lang/String;Lapp/tauri/plugin/JSObject;)V",
|
||||
&[
|
||||
id.into(),
|
||||
|
@ -5,7 +5,7 @@
|
||||
package com.plugin.sample
|
||||
|
||||
import android.app.Activity
|
||||
import app.tauri.annotation.PluginMethod
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.JSObject
|
||||
import app.tauri.plugin.Plugin
|
||||
@ -15,7 +15,7 @@ import app.tauri.plugin.Invoke
|
||||
class ExamplePlugin(private val activity: Activity): Plugin(activity) {
|
||||
private val implementation = Example()
|
||||
|
||||
@PluginMethod
|
||||
@Command
|
||||
fun ping(invoke: Invoke) {
|
||||
val value = invoke.getString("value") ?: ""
|
||||
val ret = JSObject()
|
||||
|
@ -1,7 +1,7 @@
|
||||
package {{android_package_id}}
|
||||
|
||||
import android.app.Activity
|
||||
import app.tauri.annotation.PluginMethod
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.JSObject
|
||||
import app.tauri.plugin.Plugin
|
||||
@ -11,7 +11,7 @@ import app.tauri.plugin.Invoke
|
||||
class ExamplePlugin(private val activity: Activity): Plugin(activity) {
|
||||
private val implementation = Example()
|
||||
|
||||
@PluginMethod
|
||||
@Command
|
||||
fun ping(invoke: Invoke) {
|
||||
val value = invoke.getString("value") ?: ""
|
||||
val ret = JSObject()
|
||||
|
Loading…
Reference in New Issue
Block a user