Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/extended-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": minor:feat
---

Added `onStop`, `onDestroy`, `onRestart`, `onConfigurationChanged` Android plugin hooks.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wry = { version = "0.53.4", default-features = false, features = [
"os-webview",
"linux-body",
] }
tao = { version = "0.34.2", default-features = false, features = ["rwh_06"] }
tao = { version = "0.34.4", default-features = false, features = ["rwh_06"] }
tauri-runtime = { version = "2.8.0", path = "../tauri-runtime" }
tauri-utils = { version = "2.7.0", path = "../tauri-utils" }
raw-window-handle = "0.6"
Expand Down
22 changes: 21 additions & 1 deletion crates/tauri/mobile/android-codegen/TauriActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

package {{package}}

import android.os.Bundle
import android.content.Intent
import android.content.res.Configuration
import app.tauri.plugin.PluginManager

abstract class TauriActivity : WryActivity() {
Expand All @@ -28,4 +28,24 @@ abstract class TauriActivity : WryActivity() {
super.onPause()
pluginManager.onPause()
}

override fun onRestart() {
super.onRestart()
pluginManager.onRestart()
}

override fun onStop() {
super.onStop()
pluginManager.onStop()
}

override fun onDestroy() {
super.onDestroy()
pluginManager.onDestroy()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
pluginManager.onConfigurationChanged(newConfig)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package app.tauri.plugin

import android.app.Activity
import android.content.res.Configuration
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
Expand Down Expand Up @@ -70,6 +71,28 @@ abstract class Plugin(private val activity: Activity) {
*/
open fun onResume() {}

/**
* This event is called after onStop() when the current activity is being re-displayed to the user (the user has navigated back to it).
* It will be followed by onStart() and then onResume().
*/
open fun onRestart() {}

/**
* This event is called when the app is no longer visible to the user.
* You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.
*/
open fun onStop() {}

/**
* This event is called before the activity is destroyed.
*/
open fun onDestroy() {}

/**
* This event is called when a configuration change occurs but the app does not recreate the activity.
*/
open fun onConfigurationChanged(newConfig: Configuration) {}

/**
* 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 @@ -5,6 +5,7 @@
package app.tauri.plugin

import android.app.PendingIntent
import android.content.res.Configuration
import android.content.Context
import android.content.Intent
import android.webkit.WebView
Expand Down Expand Up @@ -98,6 +99,30 @@ class PluginManager(val activity: AppCompatActivity) {
}
}

fun onRestart() {
for (plugin in plugins.values) {
plugin.instance.onRestart()
}
}

fun onStop() {
for (plugin in plugins.values) {
plugin.instance.onStop()
}
}

fun onDestroy() {
for (plugin in plugins.values) {
plugin.instance.onDestroy()
}
}

fun onConfigurationChanged(newConfig: Configuration) {
for (plugin in plugins.values) {
plugin.instance.onConfigurationChanged(newConfig)
}
}

fun startActivityForResult(intent: Intent, callback: ActivityResultCallback) {
startActivityForResultCallback = callback
startActivityForResultLauncher.launch(intent)
Expand Down
Loading