Skip to content

Commit fce7d3b

Browse files
authored
feat(core): run app cleanup code before updater restart, closes #3605 (#3616)
1 parent 58070c1 commit fce7d3b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Run `AppHandle` cleanup code before restarting the application when a new update is installed.

core/tauri/src/app.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,18 @@ impl<R: Runtime> AppHandle<R> {
289289
Ok(())
290290
}
291291

292-
/// Exits the app
292+
/// Exits the app. This is the same as [`std::process::exit`], but it performs cleanup on this application.
293293
pub fn exit(&self, exit_code: i32) {
294294
self.cleanup_before_exit();
295295
std::process::exit(exit_code);
296296
}
297297

298+
/// Restarts the app. This is the same as [`crate::api::process::restart`], but it performs cleanup on this application.
299+
pub fn restart(&self) {
300+
self.cleanup_before_exit();
301+
crate::api::process::restart(&self.env());
302+
}
303+
298304
/// Runs necessary cleanup tasks before exiting the process
299305
fn cleanup_before_exit(&self) {
300306
#[cfg(shell_execute)]

core/tauri/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ impl<A: Assets> Context<A> {
399399
// TODO: expand these docs
400400
/// Manages a running application.
401401
pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
402+
/// The application handle associated with this manager.
403+
fn app_handle(&self) -> AppHandle<R> {
404+
sealed::ManagerBase::app_handle(self)
405+
}
406+
402407
/// The [`Config`] the manager was created with.
403408
fn config(&self) -> Arc<Config> {
404409
self.manager().config()

core/tauri/src/updater/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,7 @@ mod error;
333333
pub use self::error::Error;
334334

335335
use crate::{
336-
api::{dialog::blocking::ask, process::restart},
337-
runtime::Runtime,
338-
utils::config::UpdaterConfig,
339-
Env, Manager, Window,
336+
api::dialog::blocking::ask, runtime::Runtime, utils::config::UpdaterConfig, Env, Manager, Window,
340337
};
341338

342339
/// Check for new updates
@@ -560,14 +557,13 @@ Release Notes:
560557
updater.download_and_install(pubkey.clone()).await?;
561558

562559
// Ask user if we need to restart the application
563-
let env = window.state::<Env>().inner().clone();
564560
let should_exit = ask(
565561
Some(&window),
566562
"Ready to Restart",
567563
"The installation was successful, do you want to restart the application now?",
568564
);
569565
if should_exit {
570-
restart(&env);
566+
window.app_handle().restart();
571567
}
572568
}
573569

0 commit comments

Comments
 (0)