From c968d179b154d78c967eacdcbe17a47c0ef69111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Tue, 7 Apr 2026 03:30:48 +0800 Subject: [PATCH] style: cargo fmt --- src-tauri/src/commands/config.rs | 76 +++++++++++++++++++++++------- src-tauri/src/commands/service.rs | 3 +- src-tauri/src/commands/skillhub.rs | 9 ++-- src-tauri/src/commands/skills.rs | 8 ++-- 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index 8ff096e..7f3c716 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -5368,7 +5368,8 @@ pub fn scan_git_paths() -> Result { #[cfg(target_os = "windows")] { let pf = std::env::var("ProgramFiles").unwrap_or_else(|_| r"C:\Program Files".into()); - let pf86 = std::env::var("ProgramFiles(x86)").unwrap_or_else(|_| r"C:\Program Files (x86)".into()); + let pf86 = + std::env::var("ProgramFiles(x86)").unwrap_or_else(|_| r"C:\Program Files (x86)".into()); let localappdata = std::env::var("LOCALAPPDATA").unwrap_or_default(); // 标准安装路径 @@ -5378,16 +5379,25 @@ pub fn scan_git_paths() -> Result { // 常见盘符 for drive in &["C", "D", "E", "F", "G"] { candidates.push((format!(r"{}:\Git\cmd\git.exe", drive), "MANUAL".into())); - candidates.push((format!(r"{}:\Program Files\Git\cmd\git.exe", drive), "SYSTEM".into())); + candidates.push(( + format!(r"{}:\Program Files\Git\cmd\git.exe", drive), + "SYSTEM".into(), + )); // 工具目录 for sub in &["Tools", "Dev", "AI", "Apps", "Software"] { - candidates.push((format!(r"{}:\{}\Git\cmd\git.exe", drive, sub), "MANUAL".into())); + candidates.push(( + format!(r"{}:\{}\Git\cmd\git.exe", drive, sub), + "MANUAL".into(), + )); } } // 自定义应用目录(如 D:\Data\exeApp\Git) for drive in &["C", "D", "E", "F"] { - candidates.push((format!(r"{}:\Data\exeApp\Git\cmd\git.exe", drive), "MANUAL".into())); + candidates.push(( + format!(r"{}:\Data\exeApp\Git\cmd\git.exe", drive), + "MANUAL".into(), + )); } // GitHub Desktop 内置 Git @@ -5398,9 +5408,17 @@ pub fn scan_git_paths() -> Result { for entry in entries.flatten() { let p = entry.path(); if p.is_dir() { - let git_exe = p.join("resources").join("app").join("git").join("cmd").join("git.exe"); + let git_exe = p + .join("resources") + .join("app") + .join("git") + .join("cmd") + .join("git.exe"); if git_exe.exists() { - candidates.push((git_exe.to_string_lossy().to_string(), "GITHUB_DESKTOP".into())); + candidates.push(( + git_exe.to_string_lossy().to_string(), + "GITHUB_DESKTOP".into(), + )); } } } @@ -5419,17 +5437,27 @@ pub fn scan_git_paths() -> Result { // MinGW / MSYS2 / Git Bash candidates.push((format!(r"{}\Git\mingw64\bin\git.exe", pf), "MINGW".into())); for drive in &["C", "D"] { - candidates.push((format!(r"{}:\msys64\usr\bin\git.exe", drive), "MSYS2".into())); + candidates.push(( + format!(r"{}:\msys64\usr\bin\git.exe", drive), + "MSYS2".into(), + )); candidates.push((format!(r"{}:\msys2\usr\bin\git.exe", drive), "MSYS2".into())); } // Scoop let home = dirs::home_dir().unwrap_or_default(); - candidates.push((format!(r"{}\scoop\apps\git\current\cmd\git.exe", home.display()), "SCOOP".into())); - candidates.push((format!(r"{}\scoop\shims\git.exe", home.display()), "SCOOP".into())); + candidates.push(( + format!(r"{}\scoop\apps\git\current\cmd\git.exe", home.display()), + "SCOOP".into(), + )); + candidates.push(( + format!(r"{}\scoop\shims\git.exe", home.display()), + "SCOOP".into(), + )); // Chocolatey - let choco_dir = std::env::var("ChocolateyInstall").unwrap_or_else(|_| r"C:\ProgramData\chocolatey".into()); + let choco_dir = std::env::var("ChocolateyInstall") + .unwrap_or_else(|_| r"C:\ProgramData\chocolatey".into()); candidates.push((format!(r"{}\bin\git.exe", choco_dir), "CHOCOLATEY".into())); } @@ -5439,15 +5467,27 @@ pub fn scan_git_paths() -> Result { candidates.push(("/usr/local/bin/git".into(), "SYSTEM".into())); candidates.push(("/opt/homebrew/bin/git".into(), "BREW".into())); // Xcode - candidates.push(("/Library/Developer/CommandLineTools/usr/bin/git".into(), "XCODE_CLT".into())); - candidates.push(("/Applications/Xcode.app/Contents/Developer/usr/bin/git".into(), "XCODE".into())); + candidates.push(( + "/Library/Developer/CommandLineTools/usr/bin/git".into(), + "XCODE_CLT".into(), + )); + candidates.push(( + "/Applications/Xcode.app/Contents/Developer/usr/bin/git".into(), + "XCODE".into(), + )); // Snap / Flatpak candidates.push(("/snap/bin/git".into(), "SNAP".into())); // Nix let home = dirs::home_dir().unwrap_or_default(); - candidates.push((format!("{}/.nix-profile/bin/git", home.display()), "NIX".into())); + candidates.push(( + format!("{}/.nix-profile/bin/git", home.display()), + "NIX".into(), + )); // Linuxbrew - candidates.push((format!("{}/.linuxbrew/bin/git", home.display()), "BREW".into())); + candidates.push(( + format!("{}/.linuxbrew/bin/git", home.display()), + "BREW".into(), + )); candidates.push(("/home/linuxbrew/.linuxbrew/bin/git".into(), "BREW".into())); } @@ -5455,9 +5495,13 @@ pub fn scan_git_paths() -> Result { let mut seen: std::collections::HashSet = std::collections::HashSet::new(); for (path, source) in &candidates { let p = std::path::Path::new(path); - if !p.exists() { continue; } + if !p.exists() { + continue; + } let canonical = p.to_string_lossy().to_string(); - if seen.contains(&canonical) { continue; } + if seen.contains(&canonical) { + continue; + } seen.insert(canonical.clone()); let mut cmd = Command::new(path); diff --git a/src-tauri/src/commands/service.rs b/src-tauri/src/commands/service.rs index 467ba3f..ec813db 100644 --- a/src-tauri/src/commands/service.rs +++ b/src-tauri/src/commands/service.rs @@ -154,8 +154,7 @@ fn should_auto_claim_gateway(owner: &Option) -> bool { None => true, // 无 owner 文件 → 自动认领 Some(record) => { // owner 文件存在但签名不完全匹配 → 仅按 port + openclaw_dir 判断 - record.port == port - && normalize_owned_path(&record.openclaw_dir) == openclaw_dir + record.port == port && normalize_owned_path(&record.openclaw_dir) == openclaw_dir } } } diff --git a/src-tauri/src/commands/skillhub.rs b/src-tauri/src/commands/skillhub.rs index 64c5f2c..d856867 100644 --- a/src-tauri/src/commands/skillhub.rs +++ b/src-tauri/src/commands/skillhub.rs @@ -182,15 +182,12 @@ fn extract_zip(zip_bytes: &[u8], target_dir: &Path) -> Result<(), String> { // 清理旧目录 if target_dir.exists() { - std::fs::remove_dir_all(target_dir) - .map_err(|e| format!("清理旧目录失败: {e}"))?; + std::fs::remove_dir_all(target_dir).map_err(|e| format!("清理旧目录失败: {e}"))?; } - std::fs::create_dir_all(target_dir) - .map_err(|e| format!("创建目录失败: {e}"))?; + std::fs::create_dir_all(target_dir).map_err(|e| format!("创建目录失败: {e}"))?; let reader = Cursor::new(zip_bytes); - let mut archive = - ZipArchive::new(reader).map_err(|e| format!("打开 zip 失败: {e}"))?; + let mut archive = ZipArchive::new(reader).map_err(|e| format!("打开 zip 失败: {e}"))?; // 收集所有文件名,检测是否都在同一个顶层目录下(常见的 zip 打包方式) let names: Vec = (0..archive.len()) diff --git a/src-tauri/src/commands/skills.rs b/src-tauri/src/commands/skills.rs index ff96811..0b29c01 100644 --- a/src-tauri/src/commands/skills.rs +++ b/src-tauri/src/commands/skills.rs @@ -13,8 +13,7 @@ pub async fn skills_list() -> Result { /// 查看单个 Skill 详情(纯本地文件解析,不依赖 CLI) #[tauri::command] pub async fn skills_info(name: String) -> Result { - scan_custom_skill_detail(&name) - .ok_or_else(|| format!("Skill「{name}」不存在")) + scan_custom_skill_detail(&name).ok_or_else(|| format!("Skill「{name}」不存在")) } /// 检查 Skills 依赖状态(纯本地扫描) @@ -22,7 +21,10 @@ pub async fn skills_info(name: String) -> Result { pub async fn skills_check() -> Result { let skills = scan_local_skill_entries()?; let total = skills.len(); - let ready = skills.iter().filter(|s| s.get("eligible").and_then(|v| v.as_bool()).unwrap_or(false)).count(); + let ready = skills + .iter() + .filter(|s| s.get("eligible").and_then(|v| v.as_bool()).unwrap_or(false)) + .count(); let missing = total - ready; Ok(serde_json::json!({ "total": total,