Skip to content

Commit

Permalink
feat(android): add onNewIntent plugin hook (#6780)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Apr 23, 2023
1 parent 2a5175a commit d693e52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/on-new-intent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Added the `onNewIntent` Plugin hook on Android.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit d693e52

Please sign in to comment.