From bd1fa7008b2546eea9ce6f65d65335c99fb128ae Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 30 Apr 2026 11:38:10 -0300 Subject: [PATCH 1/2] feat: changes for tauri 0.36 --- .../mobile/android-codegen/TauriActivity.kt | 35 ++++++++----------- .../src/main/java/app/tauri/plugin/Plugin.kt | 35 ++++++++++++++++++- .../java/app/tauri/plugin/PluginManager.kt | 12 +++---- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/crates/tauri/mobile/android-codegen/TauriActivity.kt b/crates/tauri/mobile/android-codegen/TauriActivity.kt index d4c2cbaad95f..2000dbff9a70 100644 --- a/crates/tauri/mobile/android-codegen/TauriActivity.kt +++ b/crates/tauri/mobile/android-codegen/TauriActivity.kt @@ -9,26 +9,6 @@ package {{package}} import android.content.Intent import android.content.res.Configuration import app.tauri.plugin.PluginManager -import androidx.lifecycle.DefaultLifecycleObserver -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.ProcessLifecycleOwner - -object TauriLifecycleObserver : DefaultLifecycleObserver { - override fun onResume(owner: LifecycleOwner) { - super.onResume(owner) - PluginManager.onResume() - } - - override fun onPause(owner: LifecycleOwner) { - super.onPause(owner) - PluginManager.onPause() - } - - override fun onStop(owner: LifecycleOwner) { - super.onStop(owner) - PluginManager.onStop() - } -} abstract class TauriActivity : WryActivity() { override val handleBackNavigation: Boolean = false @@ -47,6 +27,21 @@ abstract class TauriActivity : WryActivity() { PluginManager.onRestart(this) } + override fun onResume() { + super.onResume() + PluginManager.onResume(this) + } + + override fun onPause() { + super.onPause() + PluginManager.onPause(this) + } + + override fun onStop() { + super.onStop() + PluginManager.onStop(this) + } + override fun onDestroy() { super.onDestroy() PluginManager.onDestroy(this) diff --git a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt index fda20dd03f07..91fd221718d0 100644 --- a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt +++ b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt @@ -65,13 +65,24 @@ abstract class Plugin(private val activity: Activity) { /** * This event is called just before another activity comes into the foreground. */ + open fun onPause(activity: AppCompatActivity) {} + + /** + * This event is called just before another activity comes into the foreground. + */ + @Deprecated("use onPause(activity: AppCompatActivity) instead") open fun onPause() {} /** * This event is called when the user returns to the activity. It is also called on cold starts. */ - open fun onResume() {} + open fun onResume(activity: AppCompatActivity) {} + /** + * This event is called when the user returns to the activity. It is also called on cold starts. + */ + @Deprecated("use onResume(activity: AppCompatActivity) instead") + 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). @@ -90,6 +101,13 @@ abstract class Plugin(private val activity: Activity) { * 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(activity: AppCompatActivity) {} + + /** + * 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. + */ + @Deprecated("use onStop(activity: AppCompatActivity) instead") open fun onStop() {} /** @@ -112,6 +130,21 @@ abstract class Plugin(private val activity: Activity) { onRestart() } + internal fun triggerOnPause(activity: AppCompatActivity) { + onPause(activity) + onPause() + } + + internal fun triggerOnResume(activity: AppCompatActivity) { + onResume(activity) + onResume() + } + + internal fun triggerOnStop(activity: AppCompatActivity) { + onStop(activity) + onStop() + } + /** * This event is called when a configuration change occurs but the app does not recreate the activity. */ diff --git a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt index 0c64bb5f3411..c5657cec9ebb 100644 --- a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt +++ b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt @@ -92,15 +92,15 @@ object PluginManager { } } - fun onPause() { + fun onPause(activity: AppCompatActivity) { for (plugin in plugins.values) { - plugin.instance.onPause() + plugin.instance.triggerOnPause(activity) } } - fun onResume() { + fun onResume(activity: AppCompatActivity) { for (plugin in plugins.values) { - plugin.instance.onResume() + plugin.instance.triggerOnResume(activity) } } @@ -110,9 +110,9 @@ object PluginManager { } } - fun onStop() { + fun onStop(activity: AppCompatActivity) { for (plugin in plugins.values) { - plugin.instance.onStop() + plugin.instance.triggerOnStop(activity) } } From 7c9c3aec85213e621c485b4b072278b5edd21b60 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 30 Jul 2026 17:30:57 +0800 Subject: [PATCH 2/2] Tao 0.36 wry 0.56 events (#15789) * use git version of tao and wry * Migrate window events * use my wry branch * Gate behind mobile * tao 0.36 * wry 0.56 and dom_query 0.28 * change tag * Use `onCreate` exclusively --- .changes/mobile-resumed-suspended-event.md | 6 ++ .changes/update-dom-query.md | 5 ++ Cargo.lock | 63 ++++++++++++------- crates/tauri-runtime-wry/Cargo.toml | 11 +--- crates/tauri-runtime-wry/src/lib.rs | 48 +++----------- crates/tauri-utils/Cargo.toml | 2 +- .../mobile/android-codegen/TauriActivity.kt | 2 +- .../java/app/tauri/plugin/PluginManager.kt | 2 +- 8 files changed, 67 insertions(+), 72 deletions(-) create mode 100644 .changes/mobile-resumed-suspended-event.md create mode 100644 .changes/update-dom-query.md diff --git a/.changes/mobile-resumed-suspended-event.md b/.changes/mobile-resumed-suspended-event.md new file mode 100644 index 000000000000..a7e8d89c6a45 --- /dev/null +++ b/.changes/mobile-resumed-suspended-event.md @@ -0,0 +1,6 @@ +--- +"tauri": minor:changes +"tauri-runtime-wry": minor:changes +--- + +`WindowEvent::Resumed` and `WindowEvent::Suspended` are now only fired for the matching activity window instead of every window. diff --git a/.changes/update-dom-query.md b/.changes/update-dom-query.md new file mode 100644 index 000000000000..edfe93528c1f --- /dev/null +++ b/.changes/update-dom-query.md @@ -0,0 +1,5 @@ +--- +"tauri-utils": minor:deps +--- + +Updated `dom_query` dependency to 0.28.0 diff --git a/Cargo.lock b/Cargo.lock index 34b4061fcc40..3f3f1b322546 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1744,7 +1744,7 @@ version = "0.29.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93d03419cb5950ccfd3daf3ff1c7a36ace64609a1a8746d493df1ca0afde0fa" dependencies = [ - "cssparser-macros", + "cssparser-macros 0.6.1", "dtoa-short", "itoa", "matches", @@ -1757,11 +1757,11 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.36.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dae61cf9c0abb83bd659dab65b7e4e38d8236824c85f0f804f173567bda257d2" +checksum = "8c9cdaae01d5ed7882b04d795e7f752f46ff52d2fa3b50a20d28c464510bba98" dependencies = [ - "cssparser-macros", + "cssparser-macros 0.7.0", "dtoa-short", "itoa", "phf 0.13.1", @@ -1778,6 +1778,16 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "cssparser-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a2a99df6e410a8ff4245aa2006499ea662245f967cc7c0a38c83ef8eb44dbf" +dependencies = [ + "quote", + "syn 2.0.117", +] + [[package]] name = "ct-codecs" version = "1.1.7" @@ -2219,16 +2229,16 @@ dependencies = [ [[package]] name = "dom_query" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521e380c0c8afb8d9a1e83a1822ee03556fc3e3e7dbc1fd30be14e37f9cb3f89" +checksum = "fac5fca71e65e94cc718a6e2af65d6e0f9c6027751c2aa562fbb5087fda639bc" dependencies = [ "bit-set", - "cssparser 0.36.0", + "cssparser 0.37.0", "foldhash 0.2.0", - "html5ever 0.38.0", + "html5ever 0.39.0", "precomputed-hash", - "selectors 0.36.1", + "selectors 0.38.0", "tendril 0.5.0", ] @@ -3484,12 +3494,12 @@ dependencies = [ [[package]] name = "html5ever" -version = "0.38.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1054432bae2f14e0061e33d23402fbaa67a921d319d56adc6bcf887ddad1cbc2" +checksum = "46a1761807faccc9a19e86944bbf40610014066306f96edcdedc2fb714bcb7b8" dependencies = [ "log", - "markup5ever 0.38.0", + "markup5ever 0.39.0", ] [[package]] @@ -4654,9 +4664,9 @@ dependencies = [ [[package]] name = "markup5ever" -version = "0.38.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8983d30f2915feeaaab2d6babdd6bc7e9ed1a00b66b5e6d74df19aa9c0e91862" +checksum = "7122d987ec5f704ee56f6e5b41a7d93722e9aae27ae07cafa4036c4d3f9757de" dependencies = [ "log", "tendril 0.5.0", @@ -4935,6 +4945,12 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + [[package]] name = "ndk-sys" version = "0.6.0+11769913" @@ -7876,12 +7892,12 @@ dependencies = [ [[package]] name = "selectors" -version = "0.36.1" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d9c0c92a92d33f08817311cf3f2c29a3538a8240e94a6a3c622ce652d7e00c" +checksum = "8adfa1c298912827b8a28b223b3b874357397ae706e6190acd9bf28cee99114d" dependencies = [ "bitflags 2.13.0", - "cssparser 0.36.0", + "cssparser 0.37.0", "derive_more 2.0.1", "log", "new_debug_unreachable", @@ -8904,9 +8920,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cf65722394c2ac443e80120064987f8914ee1d4e4e36e63cdf10f2990f01159" +checksum = "e9fa4618f999c4249db1681cba0a19b890718f274de7fa93c445d46bd3a8a999" dependencies = [ "bitflags 2.13.0", "block2 0.6.2", @@ -8924,6 +8940,7 @@ dependencies = [ "libc", "log", "ndk", + "ndk-context", "ndk-sys", "objc2 0.6.4", "objc2-app-kit", @@ -8944,9 +8961,9 @@ dependencies = [ [[package]] name = "tao-macros" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd" +checksum = "5f7eeb6d99155545da6150a1795945f16ac9c178deb2a5f2e74d776107bd5849" dependencies = [ "proc-macro2", "quote", @@ -11354,9 +11371,9 @@ checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" [[package]] name = "wry" -version = "0.55.0" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3013fd6116aac351dd2e18f349b28b2cfef3a5ff3253a9d0ce2d7193bb1b4429" +checksum = "1730ab21a962e7ff44df17d20804572beee66d998afc7fcbc3f846a3a12dbda7" dependencies = [ "base64 0.22.1", "block2 0.6.2", diff --git a/crates/tauri-runtime-wry/Cargo.toml b/crates/tauri-runtime-wry/Cargo.toml index e0485cccb70b..e1873cee1b05 100644 --- a/crates/tauri-runtime-wry/Cargo.toml +++ b/crates/tauri-runtime-wry/Cargo.toml @@ -13,12 +13,11 @@ edition.workspace = true rust-version.workspace = true [dependencies] -wry = { version = "0.55.0", default-features = false, features = [ - "protocol", +wry = { version = "0.56.0", default-features = false, features = [ "os-webview", "linux-body", ] } -tao = { version = "0.35.0", default-features = false, features = ["rwh_06"] } +tao = { version = "0.36.0", default-features = false, features = ["rwh_06"] } tauri-runtime = { version = "2.11.3", path = "../tauri-runtime" } tauri-utils = { version = "2.9.3", path = "../tauri-utils" } raw-window-handle = "0.6" @@ -62,11 +61,7 @@ jni = "0.21" default = ["x11", "dbus"] devtools = ["wry/devtools", "tauri-runtime/devtools"] x11 = ["tao/x11", "wry/x11"] -macos-private-api = [ - "wry/fullscreen", - "wry/transparent", - "tauri-runtime/macos-private-api", -] +macos-private-api = ["tauri-runtime/macos-private-api"] # TODO: Remove in v3 - wry does not have this feature anymore objc-exception = [] tracing = ["dep:tracing", "wry/tracing"] diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 4a6262222b97..1d59fc5b4fe4 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -495,10 +495,7 @@ impl TryFrom> for TaoIcon { pub struct WindowEventWrapper(pub Option); impl WindowEventWrapper { - fn map_from_tao( - event: &TaoWindowEvent<'_>, - #[allow(unused_variables)] window: &WindowWrapper, - ) -> Self { + fn map_from_tao(event: &TaoWindowEvent<'_>, #[cfg(windows)] window: &WindowWrapper) -> Self { let event = match event { TaoWindowEvent::Resized(size) => WindowEvent::Resized(*size), TaoWindowEvent::Moved(position) => WindowEvent::Moved(*position), @@ -557,6 +554,10 @@ impl WindowEventWrapper { } } TaoWindowEvent::ThemeChanged(theme) => WindowEvent::ThemeChanged(map_theme(theme)), + #[cfg(mobile)] + TaoWindowEvent::Suspended => WindowEvent::Suspended, + #[cfg(mobile)] + TaoWindowEvent::Resumed => WindowEvent::Resumed, _ => return Self(None), }; Self(Some(event)) @@ -578,7 +579,11 @@ impl WindowEventWrapper { Self(None) } } - e => Self::map_from_tao(e, window), + e => Self::map_from_tao( + e, + #[cfg(windows)] + window, + ), } } } @@ -4334,39 +4339,6 @@ fn handle_event_loop( Event::SceneRequested { scene, options } => { callback(RunEvent::SceneRequested { scene, options }); } - #[cfg(mobile)] - e @ Event::Resumed | e @ Event::Suspended => { - let event = match e { - Event::Resumed => WindowEvent::Resumed, - Event::Suspended => WindowEvent::Suspended, - _ => unreachable!(), - }; - - // Collect the per-window listener handles and release the `windows` - // borrow before dispatching: handlers and the `RunEvent` callback may - // create or close windows (`windows.0.borrow_mut()`), which would panic - // the `RefCell` if we held the borrow across them. The desktop - // `WindowEvent` branches drop the borrow before dispatching for the same - // reason; this mobile `Resumed`/`Suspended` branch was the exception. - let targets = windows - .0 - .borrow() - .values() - .map(|w| (w.label.clone(), w.window_event_listeners.clone())) - .collect::>(); - - for (label, window_event_listeners) in targets { - let listeners = window_event_listeners.lock().unwrap(); - for handler in listeners.values() { - handler(&event); - } - - callback(RunEvent::WindowEvent { - label, - event: event.clone(), - }); - } - } _ => (), } } diff --git a/crates/tauri-utils/Cargo.toml b/crates/tauri-utils/Cargo.toml index 033db717352a..1b7425c67807 100644 --- a/crates/tauri-utils/Cargo.toml +++ b/crates/tauri-utils/Cargo.toml @@ -24,7 +24,7 @@ brotli = { version = "8", optional = true, default-features = false, features = url = { version = "2", features = ["serde"] } html5ever = { version = "0.29", optional = true } kuchiki = { package = "kuchikiki", version = "0.8.8-speedreader", optional = true } -dom_query = { version = "0.27", optional = true, default-features = false } +dom_query = { version = "0.28", optional = true, default-features = false } proc-macro2 = { version = "1", optional = true } quote = { version = "1", optional = true } # Our code requires at least 0.8.21 so don't change this to 0.8 diff --git a/crates/tauri/mobile/android-codegen/TauriActivity.kt b/crates/tauri/mobile/android-codegen/TauriActivity.kt index c6c9ce6b3626..0cfbe3f51be5 100644 --- a/crates/tauri/mobile/android-codegen/TauriActivity.kt +++ b/crates/tauri/mobile/android-codegen/TauriActivity.kt @@ -16,7 +16,7 @@ abstract class TauriActivity : WryActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - PluginManager.onActivityCreate(this) + PluginManager.onCreate(this) } fun getPluginManager(): PluginManager { diff --git a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt index c5657cec9ebb..a140e7447c35 100644 --- a/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt +++ b/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt @@ -55,7 +55,7 @@ object PluginManager { .registerModule(SimpleModule().addDeserializer(Channel::class.java, channelDeserializer)) } - fun onActivityCreate(activity: AppCompatActivity) { + fun onCreate(activity: AppCompatActivity) { // TODO: on destroy, we should change to a different activity if (::activity.isInitialized) { return