mirror of https://github.com/tauri-apps/tauri
This commit is contained in:
parent
58070c1eb4
commit
fce7d3bbae
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Run `AppHandle` cleanup code before restarting the application when a new update is installed.
|
|
@ -289,12 +289,18 @@ impl<R: Runtime> AppHandle<R> {
|
|||
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)]
|
||||
|
|
|
@ -399,6 +399,11 @@ impl<A: Assets> Context<A> {
|
|||
// TODO: expand these docs
|
||||
/// Manages a running application.
|
||||
pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
|
||||
/// The application handle associated with this manager.
|
||||
fn app_handle(&self) -> AppHandle<R> {
|
||||
sealed::ManagerBase::app_handle(self)
|
||||
}
|
||||
|
||||
/// The [`Config`] the manager was created with.
|
||||
fn config(&self) -> Arc<Config> {
|
||||
self.manager().config()
|
||||
|
|
|
@ -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::<Env>().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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue