diff --git a/.changes/updater-restart-cleanup.md b/.changes/updater-restart-cleanup.md new file mode 100644 index 000000000..4f9525e13 --- /dev/null +++ b/.changes/updater-restart-cleanup.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Run `AppHandle` cleanup code before restarting the application when a new update is installed. diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 7f90516b8..aedfc0c7a 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -289,12 +289,18 @@ impl AppHandle { Ok(()) } - /// Exits the app + /// Exits the app. This is the same as [`std::process::exit`], but it performs cleanup on this application. pub fn exit(&self, exit_code: i32) { self.cleanup_before_exit(); std::process::exit(exit_code); } + /// Restarts the app. This is the same as [`crate::api::process::restart`], but it performs cleanup on this application. + pub fn restart(&self) { + self.cleanup_before_exit(); + crate::api::process::restart(&self.env()); + } + /// Runs necessary cleanup tasks before exiting the process fn cleanup_before_exit(&self) { #[cfg(shell_execute)] diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index 8688ca18d..496d32218 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -399,6 +399,11 @@ impl Context { // TODO: expand these docs /// Manages a running application. pub trait Manager: sealed::ManagerBase { + /// The application handle associated with this manager. + fn app_handle(&self) -> AppHandle { + sealed::ManagerBase::app_handle(self) + } + /// The [`Config`] the manager was created with. fn config(&self) -> Arc { self.manager().config() diff --git a/core/tauri/src/updater/mod.rs b/core/tauri/src/updater/mod.rs index 4c0465216..7254d551f 100644 --- a/core/tauri/src/updater/mod.rs +++ b/core/tauri/src/updater/mod.rs @@ -333,10 +333,7 @@ mod error; pub use self::error::Error; use crate::{ - api::{dialog::blocking::ask, process::restart}, - runtime::Runtime, - utils::config::UpdaterConfig, - Env, Manager, Window, + api::dialog::blocking::ask, runtime::Runtime, utils::config::UpdaterConfig, Env, Manager, Window, }; /// Check for new updates @@ -560,14 +557,13 @@ Release Notes: updater.download_and_install(pubkey.clone()).await?; // Ask user if we need to restart the application - let env = window.state::().inner().clone(); let should_exit = ask( Some(&window), "Ready to Restart", "The installation was successful, do you want to restart the application now?", ); if should_exit { - restart(&env); + window.app_handle().restart(); } }