|
@@ -8,6 +8,7 @@ use super::config::{get_git_mirror_config, get_nodejs_mirror_config};
|
|
|
pub struct InstalledInfo {
|
|
pub struct InstalledInfo {
|
|
|
pub installed: bool,
|
|
pub installed: bool,
|
|
|
pub version: Option<String>,
|
|
pub version: Option<String>,
|
|
|
|
|
+ pub path: Option<String>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
#[derive(Serialize, Deserialize)]
|
|
@@ -75,7 +76,7 @@ async fn check_single_software(software: &str) -> InstalledInfo {
|
|
|
"vscode" => "code --version",
|
|
"vscode" => "code --version",
|
|
|
"git" => "git --version",
|
|
"git" => "git --version",
|
|
|
"claudeCode" => "claude --version",
|
|
"claudeCode" => "claude --version",
|
|
|
- _ => return InstalledInfo { installed: false, version: None },
|
|
|
|
|
|
|
+ _ => return InstalledInfo { installed: false, version: None, path: None },
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 使用 shell 执行以获取最新的 PATH 环境变量
|
|
// 使用 shell 执行以获取最新的 PATH 环境变量
|
|
@@ -112,18 +113,82 @@ async fn check_single_software(software: &str) -> InstalledInfo {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // 获取安装路径
|
|
|
|
|
+ let path = get_software_path(software).await;
|
|
|
|
|
+
|
|
|
InstalledInfo {
|
|
InstalledInfo {
|
|
|
installed: true,
|
|
installed: true,
|
|
|
version,
|
|
version,
|
|
|
|
|
+ path,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
_ => InstalledInfo {
|
|
_ => InstalledInfo {
|
|
|
installed: false,
|
|
installed: false,
|
|
|
version: None,
|
|
version: None,
|
|
|
|
|
+ path: None,
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 获取软件的安装路径
|
|
|
|
|
+async fn get_software_path(software: &str) -> Option<String> {
|
|
|
|
|
+ #[cfg(target_os = "windows")]
|
|
|
|
|
+ {
|
|
|
|
|
+ let cmd = match software {
|
|
|
|
|
+ "nodejs" => "where node",
|
|
|
|
|
+ "vscode" => "where code",
|
|
|
|
|
+ "git" => "where git",
|
|
|
|
|
+ "pnpm" => "where pnpm",
|
|
|
|
|
+ "claudeCode" => "where claude",
|
|
|
|
|
+ _ => return None,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if let Ok(output) = run_shell_hidden(cmd) {
|
|
|
|
|
+ if output.status.success() {
|
|
|
|
|
+ let path_str = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
+ let first_path = path_str.lines().next().unwrap_or("").trim();
|
|
|
|
|
+ if !first_path.is_empty() {
|
|
|
|
|
+ // 获取可执行文件所在目录的父目录(安装目录)
|
|
|
|
|
+ let path = std::path::Path::new(first_path);
|
|
|
|
|
+ // 对于不同软件,安装目录层级不同
|
|
|
|
|
+ let install_dir = match software {
|
|
|
|
|
+ "nodejs" => path.parent(), // node.exe 在安装目录下
|
|
|
|
|
+ "vscode" => path.parent().and_then(|p| p.parent()), // code.cmd 在 bin 目录下
|
|
|
|
|
+ "git" => path.parent().and_then(|p| p.parent()), // git.exe 在 cmd 目录下
|
|
|
|
|
+ _ => path.parent(),
|
|
|
|
|
+ };
|
|
|
|
|
+ return install_dir.map(|p| p.to_string_lossy().to_string());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ None
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[cfg(not(target_os = "windows"))]
|
|
|
|
|
+ {
|
|
|
|
|
+ let cmd = match software {
|
|
|
|
|
+ "nodejs" => "which node",
|
|
|
|
|
+ "vscode" => "which code",
|
|
|
|
|
+ "git" => "which git",
|
|
|
|
|
+ "pnpm" => "which pnpm",
|
|
|
|
|
+ "claudeCode" => "which claude",
|
|
|
|
|
+ _ => return None,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if let Ok(output) = run_shell_hidden(cmd) {
|
|
|
|
|
+ if output.status.success() {
|
|
|
|
|
+ let path_str = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
+ let first_path = path_str.lines().next().unwrap_or("").trim();
|
|
|
|
|
+ if !first_path.is_empty() {
|
|
|
|
|
+ let path = std::path::Path::new(first_path);
|
|
|
|
|
+ return path.parent().map(|p| p.to_string_lossy().to_string());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ None
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 获取软件版本列表
|
|
/// 获取软件版本列表
|
|
|
#[tauri::command]
|
|
#[tauri::command]
|
|
|
pub async fn get_versions(software: String) -> Result<VersionResult, String> {
|
|
pub async fn get_versions(software: String) -> Result<VersionResult, String> {
|