Skip to content

Commit 74c437b

Browse files
Sakina Farukh AhemadSakina Farukh Ahemad
authored andcommitted
feat(core): add cleanup_before_exit hook to TauriPlugin trait and docs
1 parent 5b6c549 commit 74c437b

File tree

5 files changed

+18
-67
lines changed

5 files changed

+18
-67
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@tauri-apps/tauri': 'minor:enhance'
3+
---
4+
5+
Introduce plugin-level cleanup hooks and centralize process-tree termination logic.
6+
7+
This change:
8+
- Adds `kill_process_tree` helper to the runtime for cross-platform process-tree shutdown.
9+
- Adds a new `cleanup_before_exit` lifecycle hook to plugins and wires it so plugin authors
10+
can handle sidecar shutdown without core runtime logic.
11+
- Removes hardcoded sidecar-draining from the runtime and delegates shutdown behavior to plugins.
12+
13+
This allows plugins (such as the shell plugin) to manage their own sidecar processes cleanly
14+
and improves extensibility of the Tauri runtime. Fixes #14360.

crates/tauri/CHANGELOG.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
# Changelog
22

3-
## \[Unreleased]
4-
5-
### Enhancements
6-
7-
- Added a best-effort process tree killer and plugin-level cleanup hook:
8-
- `kill_process_tree(pid: u32)` helper (cross-platform, shell/PowerShell based).
9-
- Plugin lifecycle hook `Plugin::cleanup_before_exit` and `PluginStore::cleanup_before_exit` — the runtime now delegates shutdown cleanup to plugins (for example the shell plugin) so they can manage sidecar lifecycle and process termination.
10-
- Removed public convenience `AppHandle::register_sidecar` / `unregister_sidecar`: sidecar lifecycle and registration should be owned by the plugin responsible for spawning them.
11-
- CLI dev-run integration attempts to kill sidecar descendant processes during terminate.
12-
This ensures descendant processes spawned by sidecars are terminated while keeping process-control logic inside the plugin that owns the sidecar (Fixes #14360)
13-
143
## \[2.9.2]
154

165
### Bug Fixes

crates/tauri/PR_DRAFT.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

crates/tauri/src/plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub trait Plugin<R: Runtime>: Send {
108108
///
109109
/// Plugins can use this hook to perform any process shutdown/cleanup they need
110110
/// to do before the runtime exits (for example, killing sidecars or stopping
111-
/// background tasks). This is guaranteed to run from the thread performing
112-
/// the app cleanup/exit sequence.
111+
/// background tasks). This hook is executed inside `App::cleanup_before_exit` during application shutdown.
112+
113113
#[allow(unused_variables)]
114114
fn cleanup_before_exit(&mut self, app: &AppHandle<R>) {}
115115

crates/tauri/src/process.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ fn restart_macos_app(current_binary: &std::path::Path, env: &Env) {
144144
/// protected or system processes, or when the caller lacks sufficient
145145
/// privileges. Callers should handle and log any errors returned by this
146146
/// function.
147+
148+
// TODO: Move this helper into the `process` plugin in the plugins-workspace repo.
147149
pub fn kill_process_tree(pid: u32) -> std::io::Result<()> {
148150
#[cfg(windows)]
149151
{

0 commit comments

Comments
 (0)