From 4ade3a840fbba6f7ca9923d89c06af265fd82840 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 17 May 2026 00:34:28 +0800 Subject: [PATCH] refactor: run exit cleanup on exit request --- src-tauri/src/lib.rs | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f1f0b7416..e38a6ed2a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -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 { .. } => {