fix: restart app failed (#4974)

* fix: failed to restart app

* chore: cleanup

* chore: cargo fmt

* chore: use AsyncHandler

* chore: clippy

* chore: update
This commit is contained in:
oomeow
2025-10-09 20:08:25 +08:00
committed by GitHub
parent 14b990ad9f
commit 1357913f8b
3 changed files with 32 additions and 41 deletions

View File

@@ -3,7 +3,7 @@ use crate::{
core::{CoreManager, handle, tray},
logging_error,
process::AsyncHandler,
utils::{logging::Type, resolve},
utils::{self, logging::Type, resolve},
};
use serde_yaml_ng::{Mapping, Value};
@@ -23,6 +23,7 @@ pub async fn restart_clash_core() {
/// Restart the application
pub async fn restart_app() {
utils::server::shutdown_embedded_server();
if let Err(err) = resolve::resolve_reset_async().await {
handle::Handle::notice_message(
"restart_app::error",
@@ -34,45 +35,6 @@ pub async fn restart_app() {
let app_handle = handle::Handle::app_handle();
app_handle.restart();
// TODO: PR Ref: https://github.com/clash-verge-rev/clash-verge-rev/pull/4960
// handle::Handle::notice_message("restart_app::info", "Restarting application...");
// // Use the manual restart method consistently to ensure reliability across platforms
// // This addresses the issue where app_handle.restart() doesn't work properly on Windows
// let current_exe = match env::current_exe() {
// Ok(path) => path,
// Err(_) => {
// // If we can't get the current executable path, try to use the fallback method
// if let Some(app_handle) = handle::Handle::global().app_handle() {
// app_handle.restart();
// }
// exit(1); // If we reach here, either app_handle was None or restart() failed to restart
// }
// };
// let mut cmd = Command::new(current_exe);
// cmd.args(env::args().skip(1));
// match cmd.spawn() {
// Ok(child) => {
// log::info!(target: "app", "New application instance started with PID: {}", child.id());
// // Successfully started new process, now exit current process
// if let Some(app_handle) = handle::Handle::global().app_handle() {
// app_handle.exit(0);
// } else {
// exit(0);
// }
// }
// Err(e) => {
// log::error!(target: "app", "Failed to start new application instance: {}", e);
// // If manual spawn fails, try the original restart method as a last resort
// if let Some(app_handle) = handle::Handle::global().app_handle() {
// app_handle.restart();
// } else {
// exit(1);
// }
// }
// }
}
fn after_change_clash_mode() {

View File

@@ -1,3 +1,4 @@
use crate::utils;
use crate::utils::window_manager::WindowManager;
use crate::{
config::Config,
@@ -21,6 +22,7 @@ async fn open_or_close_dashboard_internal() {
pub async fn quit() {
logging!(debug, Type::System, true, "启动退出流程");
utils::server::shutdown_embedded_server();
// 获取应用句柄并设置退出标志
let app_handle = handle::Handle::app_handle();