diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index aa4017f1..594abd04 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -2,14 +2,14 @@ use crate::{ config::*, core::*, feat, - utils::{dirs, help}, + utils::{dirs, help, resolve}, }; use crate::{ret_err, wrap_err}; use anyhow::{Context, Result}; use serde_yaml::Mapping; use std::collections::{HashMap, VecDeque}; use sysproxy::Sysproxy; - +use tauri::api; type CmdResult = Result; #[tauri::command] @@ -266,6 +266,15 @@ pub async fn test_delay(url: String) -> CmdResult { Ok(feat::test_delay(url).await.unwrap_or(10000u32)) } +#[tauri::command] +pub fn exit_app(app_handle: tauri::AppHandle) { + let _ = resolve::save_window_size_position(&app_handle, true); + resolve::resolve_reset(); + api::process::kill_children(); + app_handle.exit(0); + std::process::exit(0); +} + #[cfg(windows)] pub mod service { use super::*; diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 3c1214be..193830ad 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -203,14 +203,8 @@ impl Tray { "open_logs_dir" => crate::log_err!(cmds::open_logs_dir()), "restart_clash" => feat::restart_clash_core(), "restart_app" => api::process::restart(&app_handle.env()), - "quit" => { - let _ = resolve::save_window_size_position(app_handle, true); + "quit" => cmds::exit_app(app_handle.clone()), - resolve::resolve_reset(); - api::process::kill_children(); - app_handle.exit(0); - std::process::exit(0); - } _ => {} }, _ => {} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index fdc19a3f..26040dde 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -55,6 +55,7 @@ fn main() -> std::io::Result<()> { cmds::get_verge_config, cmds::patch_verge_config, cmds::test_delay, + cmds::exit_app, // cmds::update_hotkeys, // profile cmds::get_profiles, @@ -102,14 +103,6 @@ fn main() -> std::io::Result<()> { .expect("error while running tauri application"); app.run(|app_handle, e| match e { - tauri::RunEvent::ExitRequested { api, .. } => { - api.prevent_exit(); - } - tauri::RunEvent::Exit => { - resolve::resolve_reset(); - api::process::kill_children(); - app_handle.exit(0); - } tauri::RunEvent::Updater(tauri::UpdaterEvent::Downloaded) => { resolve::resolve_reset(); api::process::kill_children(); diff --git a/src/components/setting/setting-verge.tsx b/src/components/setting/setting-verge.tsx index 50650c81..57c5cf3e 100644 --- a/src/components/setting/setting-verge.tsx +++ b/src/components/setting/setting-verge.tsx @@ -10,10 +10,9 @@ import { Input, Typography, } from "@mui/material"; -import { openAppDir, openCoreDir, openLogsDir } from "@/services/cmds"; +import { exitApp, openAppDir, openCoreDir, openLogsDir } from "@/services/cmds"; import { ArrowForward } from "@mui/icons-material"; import { checkUpdate } from "@tauri-apps/api/updater"; -import { exit } from "@tauri-apps/api/process"; import { useVerge } from "@/hooks/use-verge"; import { version } from "@root/package.json"; import { DialogRef, Notice } from "@/components/base"; @@ -314,7 +313,7 @@ const SettingVerge = ({ onError }: Props) => { size="small" sx={{ my: "2px" }} onClick={() => { - exit(0); + exitApp(); }} > diff --git a/src/services/cmds.ts b/src/services/cmds.ts index b1a6e44d..f46a11d4 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -199,3 +199,7 @@ export async function invoke_uwp_tool() { export async function getPortableFlag() { return invoke("get_portable_flag"); } + +export async function exitApp() { + return invoke("exit_app"); +}