style: cargo fmt

This commit is contained in:
晴天
2026-04-07 03:30:48 +08:00
parent ad00ffef3d
commit c968d179b1
4 changed files with 69 additions and 27 deletions

View File

@@ -5368,7 +5368,8 @@ pub fn scan_git_paths() -> Result<Value, String> {
#[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<Value, String> {
// 常见盘符
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<Value, String> {
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<Value, String> {
// 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<Value, String> {
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<Value, String> {
let mut seen: std::collections::HashSet<String> = 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);

View File

@@ -154,8 +154,7 @@ fn should_auto_claim_gateway(owner: &Option<GatewayOwnerRecord>) -> 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
}
}
}

View File

@@ -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<String> = (0..archive.len())

View File

@@ -13,8 +13,7 @@ pub async fn skills_list() -> Result<Value, String> {
/// 查看单个 Skill 详情(纯本地文件解析,不依赖 CLI
#[tauri::command]
pub async fn skills_info(name: String) -> Result<Value, String> {
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<Value, String> {
pub async fn skills_check() -> Result<Value, String> {
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,