浏览器下载插件

This commit is contained in:
zhongluofeng
2026-07-21 17:40:55 +08:00
parent 548b022426
commit 141547acb6
9 changed files with 1322 additions and 129 deletions
+24 -5
View File
@@ -38,14 +38,16 @@ fn quit_app(
state: tauri::State<'_, ProcessManager>,
mihomo: tauri::State<'_, MihomoManager>,
aria2: tauri::State<'_, Aria2Manager>,
app: tauri::AppHandle,
) {
// 退出前清理系统代理,避免遗留导致网络问题
mihomo.cleanup_on_exit();
// 退出前让 aria2 优雅关闭(保存 session
// 退出前让 aria2 优雅关闭(保存 session2s 超时
aria2.cleanup_on_exit();
// 停止所有子进程
// 停止所有子进程(同步 kill + 带超时的 wait,确保进程真正终止)
state.stop_all();
std::process::exit(0);
// 通过 app.exit 触发 RunEvent::ExitRequested,统一退出路径
app.exit(0);
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@@ -154,6 +156,7 @@ pub fn run() {
}
"quit" => {
// 退出前清理系统代理 + 优雅关闭 aria2 + 停止所有子进程
// 直接调用 cleanup + stop_all + exitquit_app 命令是给前端用的)
if let Some(mihomo) = app.try_state::<MihomoManager>() {
mihomo.cleanup_on_exit();
}
@@ -207,6 +210,22 @@ pub fn run() {
api.prevent_close();
}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|app, event| {
// 退出请求兜底:捕获所有退出路径(app.exit、窗口全部关闭、系统信号等)
// 确保 mihomo/aria2 子进程在任何情况下都被清理
// 注:quit_app 命令和托盘菜单已主动调用 cleanup,这里作为二次保险
if let tauri::RunEvent::ExitRequested { .. } = event {
if let Some(mihomo) = app.try_state::<MihomoManager>() {
mihomo.cleanup_on_exit();
}
if let Some(aria2) = app.try_state::<Aria2Manager>() {
aria2.cleanup_on_exit();
}
if let Some(pm) = app.try_state::<ProcessManager>() {
pm.stop_all();
}
}
});
}