mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): add stop, restart, destroy and configuration changed Android hooks (#14328)
* feat(core): add pause, destroy and configuration changed Android hooks * Apply suggestions from code review
This commit is contained in:
committed by
GitHub
parent
3397fd9bfe
commit
68cb318979
5
.changes/extended-hooks.md
Normal file
5
.changes/extended-hooks.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": minor:feat
|
||||
---
|
||||
|
||||
Added `onStop`, `onDestroy`, `onRestart`, `onConfigurationChanged` Android plugin hooks.
|
||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -8411,9 +8411,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tao"
|
||||
version = "0.34.2"
|
||||
version = "0.34.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4daa814018fecdfb977b59a094df4bd43b42e8e21f88fddfc05807e6f46efaaf"
|
||||
checksum = "6121216ff67fe4bcfe64508ea1700bc15f74937d835a07b4a209cc00a8926a84"
|
||||
dependencies = [
|
||||
"bitflags 2.7.0",
|
||||
"block2 0.6.0",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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() {
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user