diff --git a/src-tauri/src/core/backup.rs b/src-tauri/src/core/backup.rs index 3f9cfba42..5f5555cd0 100644 --- a/src-tauri/src/core/backup.rs +++ b/src-tauri/src/core/backup.rs @@ -127,13 +127,24 @@ impl WebDavClient { .set_auth(reqwest_dav::Auth::Basic(config.username, config.password)) .build()?; - // 尝试检查目录是否存在,如果不存在尝试创建,但创建失败不报错 + // 尝试检查目录是否存在,如果不存在尝试创建 if client .list(dirs::BACKUP_DIR, reqwest_dav::Depth::Number(0)) .await .is_err() { - let _ = client.mkcol(dirs::BACKUP_DIR).await; + match client.mkcol(dirs::BACKUP_DIR).await { + Ok(_) => log::info!("Successfully created backup directory"), + Err(e) => { + log::warn!("Failed to create backup directory: {}", e); + // 清除缓存,强制下次重新尝试 + self.reset(); + return Err(anyhow::Error::msg(format!( + "Failed to create backup directory: {}", + e + ))); + } + } } // 缓存客户端 diff --git a/src-tauri/src/feat/backup.rs b/src-tauri/src/feat/backup.rs index d92418c80..b20a81672 100644 --- a/src-tauri/src/feat/backup.rs +++ b/src-tauri/src/feat/backup.rs @@ -20,6 +20,8 @@ pub async fn create_backup_and_upload_webdav() -> Result<()> { .await { log::error!(target: "app", "Failed to upload to WebDAV: {err:#?}"); + // 上传失败时重置客户端缓存 + backup::WebDavClient::global().reset(); return Err(err); } diff --git a/src-tauri/src/feat/clash.rs b/src-tauri/src/feat/clash.rs index 74e4a961c..89fdfc78c 100644 --- a/src-tauri/src/feat/clash.rs +++ b/src-tauri/src/feat/clash.rs @@ -7,6 +7,8 @@ use crate::{ utils::{logging::Type, resolve}, }; use serde_yaml_ng::{Mapping, Value}; +use std::env; +use std::process::{Command, exit}; /// Restart the Clash core pub async fn restart_clash_core() { @@ -27,19 +29,40 @@ pub async fn restart_app() { // logging_error!(Type::Core, true, CoreManager::global().stop_core().await); resolve::resolve_reset_async().await; - handle::Handle::global() - .app_handle() - .map(|app_handle| { + match handle::Handle::global().app_handle() { + Some(app_handle) => { app_handle.restart(); - }) - .unwrap_or_else(|| { + } + None => { logging_error!( Type::System, false, "{}", - "Failed to get app handle for restart" + "Failed to get app handle for restart, attempting alternative restart method" ); - }); + // Fallback: launch a new instance of the application and exit the current one + + let current_exe = env::current_exe().unwrap_or_else(|_| { + exit(1); // Exit if can't find the executable path + }); + + 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 + exit(0); + } + Err(e) => { + log::error!(target: "app", "Failed to start new application instance: {}", e); + // Unable to start new process, exit with error + exit(1); + } + } + } + } } fn after_change_clash_mode() {