refactor: run exit cleanup on exit request

This commit is contained in:
Tunglies
2026-05-17 00:47:25 +08:00
parent 07cbecb01d
commit 4ade3a840f
+12 -22
View File
@@ -387,31 +387,21 @@ pub fn run() {
event_handlers::handle_reopen(has_visible_windows).await;
});
}
tauri::RunEvent::Exit => AsyncHandler::block_on(async {
// TODO: Do not perform cleanup in RunEvent::Exit.
// At this point the exit can no longer be prevented,
// so async cleanup is not reliable.
// Do not breaking changes yet version.
if !handle::Handle::global().is_exiting() {
feat::quit().await;
}
}),
tauri::RunEvent::Exit => {
logging!(info, Type::System, "Application exited");
}
#[allow(unused_variables)]
tauri::RunEvent::ExitRequested { api, code, .. }
if module::lightweight::is_in_lightweight_mode() && !handle::Handle::global().is_exiting() =>
{
{
tauri::RunEvent::ExitRequested { api, code, .. } => {
if module::lightweight::is_in_lightweight_mode() && !handle::Handle::global().is_exiting() {
api.prevent_exit();
} else if code.is_none() {
api.prevent_exit();
if !handle::Handle::global().is_exiting() {
AsyncHandler::spawn(|| async {
feat::quit().await;
});
}
}
// TODO: Migrate the cleanup logic from RunEvent::Exit to RunEvent::ExitRequested.
// This lets us call api.prevent_exit(), run async cleanup first,
// and then call app_handle.exit(code) after cleanup has completed.
// Do not breaking changes yet version.
// if Some(0) == code {
// api.prevent_exit();
// }
}
tauri::RunEvent::WindowEvent { label, event, .. } if label == "main" => match event {
tauri::WindowEvent::CloseRequested { .. } => {