黄中银 пре 2 недеља
родитељ
комит
ba2610c787
3 измењених фајлова са 87 додато и 6 уклоњено
  1. 1 0
      shared/types.ts
  2. 66 1
      src-tauri/src/commands/software.rs
  3. 20 5
      src/stores/install.ts

+ 1 - 0
shared/types.ts

@@ -65,6 +65,7 @@ export interface InstallResult {
 export interface InstalledInfo {
   installed: boolean
   version: string | null
+  path?: string | null
 }
 
 export interface AllInstalledInfo {

+ 66 - 1
src-tauri/src/commands/software.rs

@@ -8,6 +8,7 @@ use super::config::{get_git_mirror_config, get_nodejs_mirror_config};
 pub struct InstalledInfo {
     pub installed: bool,
     pub version: Option<String>,
+    pub path: Option<String>,
 }
 
 #[derive(Serialize, Deserialize)]
@@ -75,7 +76,7 @@ async fn check_single_software(software: &str) -> InstalledInfo {
         "vscode" => "code --version",
         "git" => "git --version",
         "claudeCode" => "claude --version",
-        _ => return InstalledInfo { installed: false, version: None },
+        _ => return InstalledInfo { installed: false, version: None, path: None },
     };
 
     // 使用 shell 执行以获取最新的 PATH 环境变量
@@ -112,18 +113,82 @@ async fn check_single_software(software: &str) -> InstalledInfo {
                 }
             };
 
+            // 获取安装路径
+            let path = get_software_path(software).await;
+
             InstalledInfo {
                 installed: true,
                 version,
+                path,
             }
         }
         _ => InstalledInfo {
             installed: false,
             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]
 pub async fn get_versions(software: String) -> Result<VersionResult, String> {

+ 20 - 5
src/stores/install.ts

@@ -62,11 +62,11 @@ export const useInstallStore = defineStore('install', () => {
 
   // 已安装信息
   const installedInfo = ref<AllInstalledInfo>({
-    nodejs: { installed: false, version: null },
-    pnpm: { installed: false, version: null },
-    vscode: { installed: false, version: null },
-    git: { installed: false, version: null },
-    claudeCode: { installed: false, version: null }
+    nodejs: { installed: false, version: null, path: null },
+    pnpm: { installed: false, version: null, path: null },
+    vscode: { installed: false, version: null, path: null },
+    git: { installed: false, version: null, path: null },
+    claudeCode: { installed: false, version: null, path: null }
   })
 
   // Claude Code VS Code 扩展安装状态(单独管理,因为不是通过 checkInstalled API 获取)
@@ -139,6 +139,16 @@ export const useInstallStore = defineStore('install', () => {
       const result = await window.electronAPI.checkInstalled('all') as AllInstalledInfo
       if (result) {
         installedInfo.value = result
+        // 自动填充已安装软件的路径到安装选项中
+        if (result.nodejs.installed && result.nodejs.path) {
+          installOptions.value.all.nodejsPath = result.nodejs.path
+        }
+        if (result.vscode.installed && result.vscode.path) {
+          installOptions.value.all.vscodePath = result.vscode.path
+        }
+        if (result.git.installed && result.git.path) {
+          installOptions.value.all.gitPath = result.git.path
+        }
       }
     } catch (error) {
       const errorMsg = error instanceof Error ? error.message : String(error)
@@ -221,6 +231,10 @@ export const useInstallStore = defineStore('install', () => {
     return installedInfo.value[software].version
   }
 
+  function getInstalledPath(software: SoftwareType): string | null {
+    return installedInfo.value[software].path || null
+  }
+
   // Claude Code VS Code 扩展相关方法
   async function checkClaudeCodeExtInstalled(): Promise<void> {
     try {
@@ -264,6 +278,7 @@ export const useInstallStore = defineStore('install', () => {
     getStatus,
     isInstalled,
     getInstalledVersion,
+    getInstalledPath,
     checkClaudeCodeExtInstalled,
     isClaudeCodeExtInstalled,
     getClaudeCodeExtVersion