mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:53:44 +08:00
feat: clean proxy settings before exit (#3404)
This commit is contained in:
parent
55cde38562
commit
7383459b9a
@ -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")]
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user