feat(android): add onNewIntent plugin hook (#6780)

This commit is contained in:
Lucas Fernandes Nogueira 2023-04-23 15:59:46 -07:00 committed by GitHub
parent 2a5175a8f8
commit d693e526e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch
---
Added the `onNewIntent` Plugin hook on Android.

View File

@ -30,6 +30,11 @@ abstract class Plugin(private val activity: Activity) {
return handle!!.config
}
/**
* Handle a new intent being received by the application
*/
open fun onNewIntent(intent: Intent) {}
/**
* Start activity for result with the provided Intent and resolve calling the provided callback method name.
*

View File

@ -17,7 +17,7 @@ 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, val config: JSObject) {
class PluginHandle(private val manager: PluginManager, val name: String, val instance: Plugin, val config: JSObject) {
private val commands: HashMap<String, CommandData> = HashMap()
private val permissionCallbackMethods: HashMap<String, Method> = HashMap()
private val startActivityCallbackMethods: HashMap<String, Method> = HashMap()

View File

@ -46,6 +46,12 @@ class PluginManager(val activity: AppCompatActivity) {
}
}
fun onNewIntent(intent: Intent) {
for (plugin in plugins.values) {
plugin.instance.onNewIntent(intent)
}
}
fun startActivityForResult(intent: Intent, callback: ActivityResultCallback) {
startActivityForResultCallback = callback
startActivityForResultLauncher.launch(intent)

View File

@ -1,7 +1,15 @@
package {{reverse-domain app.domain}}.{{snake-case app.name}}
import android.os.Bundle
import app.tauri.plugin.PluginManager
abstract class TauriActivity : WryActivity() {
var pluginManager: PluginManager = PluginManager(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (intent != null) {
pluginManager.onNewIntent(intent)
}
}
}