diff --git a/UPDATELOG.md b/UPDATELOG.md index a70b632e9..f7c1d5cd7 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -13,6 +13,7 @@ - 修复`DNS`覆写 `fallback` `proxy server` `nameserver` `direct Nameserver` 字段支持留空 - 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo` 库 - 修复搜索框输入特殊字符崩溃 +- 修复 Windows 下 Start UP 名称与 exe 名称不统一 ### ✨ 新增功能 diff --git a/src-tauri/src/utils/autostart.rs b/src-tauri/src/utils/autostart.rs index df04b8100..8b2e6cad6 100644 --- a/src-tauri/src/utils/autostart.rs +++ b/src-tauri/src/utils/autostart.rs @@ -39,10 +39,20 @@ pub fn get_exe_path() -> Result { pub fn create_shortcut() -> Result<()> { let exe_path = get_exe_path()?; let startup_dir = get_startup_dir()?; - let shortcut_path = startup_dir.join("Clash-Verge.lnk"); + let old_shortcut_path = startup_dir.join("Clash-Verge.lnk"); + let new_shortcut_path = startup_dir.join("Clash Verge.lnk"); - // 如果快捷方式已存在,直接返回成功 - if shortcut_path.exists() { + // 移除旧的快捷方式 + if old_shortcut_path.exists() { + if let Err(e) = fs::remove_file(&old_shortcut_path) { + info!(target: "app", "移除旧快捷方式失败: {}", e); + } else { + info!(target: "app", "成功移除旧快捷方式"); + } + } + + // 如果新快捷方式已存在,直接返回成功 + if new_shortcut_path.exists() { info!(target: "app", "启动快捷方式已存在"); return Ok(()); } @@ -53,7 +63,7 @@ pub fn create_shortcut() -> Result<()> { $Shortcut = $WshShell.CreateShortcut('{}'); \ $Shortcut.TargetPath = '{}'; \ $Shortcut.Save()", - shortcut_path.to_string_lossy().replace("\\", "\\\\"), + new_shortcut_path.to_string_lossy().replace("\\", "\\\\"), exe_path.to_string_lossy().replace("\\", "\\\\") ); @@ -77,18 +87,29 @@ pub fn create_shortcut() -> Result<()> { #[cfg(target_os = "windows")] pub fn remove_shortcut() -> Result<()> { let startup_dir = get_startup_dir()?; - let shortcut_path = startup_dir.join("Clash-Verge.lnk"); + let old_shortcut_path = startup_dir.join("Clash-Verge.lnk"); + let new_shortcut_path = startup_dir.join("Clash Verge.lnk"); - // 如果快捷方式不存在,直接返回成功 - if !shortcut_path.exists() { - info!(target: "app", "启动快捷方式不存在,无需删除"); - return Ok(()); + let mut removed_any = false; + + // 删除旧的快捷方式 + if old_shortcut_path.exists() { + fs::remove_file(&old_shortcut_path).map_err(|e| anyhow!("删除旧快捷方式失败: {}", e))?; + info!(target: "app", "成功删除旧启动快捷方式"); + removed_any = true; } - // 删除快捷方式 - fs::remove_file(&shortcut_path).map_err(|e| anyhow!("删除快捷方式失败: {}", e))?; + // 删除新的快捷方式 + if new_shortcut_path.exists() { + fs::remove_file(&new_shortcut_path).map_err(|e| anyhow!("删除快捷方式失败: {}", e))?; + info!(target: "app", "成功删除启动快捷方式"); + removed_any = true; + } + + if !removed_any { + info!(target: "app", "启动快捷方式不存在,无需删除"); + } - info!(target: "app", "成功删除启动快捷方式"); Ok(()) } @@ -96,9 +117,9 @@ pub fn remove_shortcut() -> Result<()> { #[cfg(target_os = "windows")] pub fn is_shortcut_enabled() -> Result { let startup_dir = get_startup_dir()?; - let shortcut_path = startup_dir.join("Clash-Verge.lnk"); + let new_shortcut_path = startup_dir.join("Clash Verge.lnk"); - Ok(shortcut_path.exists()) + Ok(new_shortcut_path.exists()) } // 非 Windows 平台使用的空方法