feat: clean proxy settings before exit (#3404)

This commit is contained in:
tiegen 2025-04-26 18:09:53 +08:00 committed by GitHub
parent 55cde38562
commit 7383459b9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 36 deletions

View File

@ -64,6 +64,15 @@ pub fn quit() {
// 在单独线程中处理资源清理,避免阻塞主线程
std::thread::spawn(move || {
let cleanup_result = clean();
app_handle.exit(match cleanup_result {
true => 0,
false => 1,
});
});
}
pub fn clean() -> bool {
use tokio::time::{timeout, Duration};
let rt = tokio::runtime::Runtime::new().unwrap();
let cleanup_result = rt.block_on(async {
@ -99,12 +108,7 @@ pub fn quit() {
tun_success && proxy_res.is_ok() && core_res.is_ok()
});
app_handle.exit(match cleanup_result {
true => 0,
false => 1,
});
});
cleanup_result
}
#[cfg(target_os = "macos")]

View File

@ -302,6 +302,13 @@ pub fn run() {
api.prevent_exit();
}
}
tauri::RunEvent::Exit => {
// avoid duplicate cleanup
if core::handle::Handle::global().is_exiting() {
return;
}
feat::clean();
}
tauri::RunEvent::WindowEvent { label, event, .. } => {
if label == "main" {
match event {