Przeglądaj źródła

看起来好像可以了

黄中银 2 tygodni temu
rodzic
commit
cf958b4022

+ 2 - 2
src-tauri/src/commands/config.rs

@@ -43,7 +43,7 @@ pub async fn get_git_mirror_config() -> GitMirrorConfig {
 
     // 默认配置
     GitMirrorConfig {
-        mirror: "github".to_string(),
+        mirror: "huaweicloud".to_string(),
     }
 }
 
@@ -74,7 +74,7 @@ pub async fn get_nodejs_mirror_config() -> NodejsMirrorConfig {
 
     // 默认配置
     NodejsMirrorConfig {
-        mirror: "official".to_string(),
+        mirror: "npmmirror".to_string(),
     }
 }
 

+ 46 - 16
src-tauri/src/commands/software.rs

@@ -359,36 +359,36 @@ async fn get_git_versions_from_huaweicloud(client: &reqwest::Client) -> Vec<Stri
 fn get_fallback_git_versions() -> Vec<VersionItem> {
     vec![
         VersionItem {
-            value: "2.47.1.windows.1".to_string(),
-            label: "2.47.1.windows.1".to_string(),
+            value: "2.47.1".to_string(),
+            label: "Git 2.47.1".to_string(),
             lts: None,
             disabled: None,
             separator: None,
         },
         VersionItem {
-            value: "2.47.0.windows.2".to_string(),
-            label: "2.47.0.windows.2".to_string(),
+            value: "2.47.0".to_string(),
+            label: "Git 2.47.0".to_string(),
             lts: None,
             disabled: None,
             separator: None,
         },
         VersionItem {
-            value: "2.46.2.windows.1".to_string(),
-            label: "2.46.2.windows.1".to_string(),
+            value: "2.46.2".to_string(),
+            label: "Git 2.46.2".to_string(),
             lts: None,
             disabled: None,
             separator: None,
         },
         VersionItem {
-            value: "2.46.1.windows.1".to_string(),
-            label: "2.46.1.windows.1".to_string(),
+            value: "2.46.1".to_string(),
+            label: "Git 2.46.1".to_string(),
             lts: None,
             disabled: None,
             separator: None,
         },
         VersionItem {
-            value: "2.46.0.windows.1".to_string(),
-            label: "2.46.0.windows.1".to_string(),
+            value: "2.46.0".to_string(),
+            label: "Git 2.46.0".to_string(),
             lts: None,
             disabled: None,
             separator: None,
@@ -397,15 +397,45 @@ fn get_fallback_git_versions() -> Vec<VersionItem> {
 }
 
 async fn get_vscode_versions() -> Result<VersionResult, String> {
-    // VS Code 通常只提供最新版本
-    Ok(VersionResult {
-        versions: vec![VersionItem {
-            value: "latest".to_string(),
-            label: "Latest".to_string(),
+    let client = reqwest::Client::new();
+
+    // 从 VS Code 官方 API 获取版本列表
+    let response = client
+        .get("https://update.code.visualstudio.com/api/releases/stable")
+        .header("User-Agent", "Claude-AI-Installer")
+        .timeout(std::time::Duration::from_secs(10))
+        .send()
+        .await
+        .map_err(|e| format!("请求 VS Code 版本列表失败: {}", e))?;
+
+    if !response.status().is_success() {
+        return Err(format!("VS Code API 返回错误状态: {}", response.status()));
+    }
+
+    // API 返回格式是版本号数组: ["1.96.0", "1.95.3", ...]
+    let versions: Vec<String> = response
+        .json()
+        .await
+        .map_err(|e| format!("解析 VS Code 版本列表失败: {}", e))?;
+
+    let version_items: Vec<VersionItem> = versions
+        .into_iter()
+        .take(15)
+        .map(|version| VersionItem {
+            value: version.clone(),
+            label: format!("VS Code {}", version),
             lts: None,
             disabled: None,
             separator: None,
-        }],
+        })
+        .collect();
+
+    if version_items.is_empty() {
+        return Err("VS Code 版本列表为空".to_string());
+    }
+
+    Ok(VersionResult {
+        versions: version_items,
         warning: None,
     })
 }

+ 14 - 0
src-tauri/src/commands/vscode.rs

@@ -16,6 +16,13 @@ pub struct CommandResult {
 /// 检查 VS Code 扩展是否已安装
 #[tauri::command]
 pub async fn check_vscode_extension(extension_id: String) -> ExtensionStatus {
+    // 在 Windows 上,code 实际上是 code.cmd,需要通过 cmd 调用
+    #[cfg(target_os = "windows")]
+    let output = Command::new("cmd")
+        .args(["/c", "code", "--list-extensions", "--show-versions"])
+        .output();
+
+    #[cfg(not(target_os = "windows"))]
     let output = Command::new("code")
         .args(["--list-extensions", "--show-versions"])
         .output();
@@ -53,6 +60,13 @@ pub async fn check_vscode_extension(extension_id: String) -> ExtensionStatus {
 /// 安装 VS Code 扩展
 #[tauri::command]
 pub async fn install_vscode_extension(extension_id: String) -> CommandResult {
+    // 在 Windows 上,code 实际上是 code.cmd,需要通过 cmd 调用
+    #[cfg(target_os = "windows")]
+    let output = Command::new("cmd")
+        .args(["/c", "code", "--install-extension", &extension_id, "--force"])
+        .output();
+
+    #[cfg(not(target_os = "windows"))]
     let output = Command::new("code")
         .args(["--install-extension", &extension_id, "--force"])
         .output();