fix: unify startup shortcut name to "Clash Verge" on Windows

This commit is contained in:
Tunglies
2025-07-14 04:22:06 +08:00
parent 2c9aa4bca7
commit 077f3e79f8
2 changed files with 36 additions and 14 deletions

View File

@@ -13,6 +13,7 @@
- 修复`DNS`覆写 `fallback` `proxy server` `nameserver` `direct Nameserver` 字段支持留空 - 修复`DNS`覆写 `fallback` `proxy server` `nameserver` `direct Nameserver` 字段支持留空
- 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo` - 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo`
- 修复搜索框输入特殊字符崩溃 - 修复搜索框输入特殊字符崩溃
- 修复 Windows 下 Start UP 名称与 exe 名称不统一
### ✨ 新增功能 ### ✨ 新增功能

View File

@@ -39,10 +39,20 @@ pub fn get_exe_path() -> Result<PathBuf> {
pub fn create_shortcut() -> Result<()> { pub fn create_shortcut() -> Result<()> {
let exe_path = get_exe_path()?; let exe_path = get_exe_path()?;
let startup_dir = get_startup_dir()?; 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", "启动快捷方式已存在"); info!(target: "app", "启动快捷方式已存在");
return Ok(()); return Ok(());
} }
@@ -53,7 +63,7 @@ pub fn create_shortcut() -> Result<()> {
$Shortcut = $WshShell.CreateShortcut('{}'); \ $Shortcut = $WshShell.CreateShortcut('{}'); \
$Shortcut.TargetPath = '{}'; \ $Shortcut.TargetPath = '{}'; \
$Shortcut.Save()", $Shortcut.Save()",
shortcut_path.to_string_lossy().replace("\\", "\\\\"), new_shortcut_path.to_string_lossy().replace("\\", "\\\\"),
exe_path.to_string_lossy().replace("\\", "\\\\") exe_path.to_string_lossy().replace("\\", "\\\\")
); );
@@ -77,18 +87,29 @@ pub fn create_shortcut() -> Result<()> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn remove_shortcut() -> Result<()> { pub fn remove_shortcut() -> Result<()> {
let startup_dir = get_startup_dir()?; 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");
// 如果快捷方式不存在,直接返回成功 let mut removed_any = false;
if !shortcut_path.exists() {
info!(target: "app", "启动快捷方式不存在,无需删除"); // 删除旧的快捷方式
return Ok(()); 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(()) Ok(())
} }
@@ -96,9 +117,9 @@ pub fn remove_shortcut() -> Result<()> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn is_shortcut_enabled() -> Result<bool> { pub fn is_shortcut_enabled() -> Result<bool> {
let startup_dir = get_startup_dir()?; 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 平台使用的空方法 // 非 Windows 平台使用的空方法