黄中银 2 settimane fa
parent
commit
1266c6ee02
3 ha cambiato i file con 101 aggiunte e 3 eliminazioni
  1. 59 1
      src-tauri/src/commands/install.rs
  2. 21 1
      src/i18n/en-US.ts
  3. 21 1
      src/i18n/zh-CN.ts

+ 59 - 1
src-tauri/src/commands/install.rs

@@ -72,7 +72,7 @@ pub async fn install_software(
         *cancel
     };
 
-    match software.as_str() {
+    let result = match software.as_str() {
         "nodejs" => install_nodejs(&app, &state, &options, emit_status, is_cancelled).await,
         "pnpm" => install_pnpm(&app, &state, emit_status, is_cancelled).await,
         "vscode" => install_vscode(&app, &state, &options, emit_status, is_cancelled).await,
@@ -80,7 +80,34 @@ pub async fn install_software(
         "claudeCode" => install_claude_code_software(&app, &state, emit_status, is_cancelled).await,
         "all" => install_all(&app, &state, &options, emit_status, is_cancelled).await,
         _ => Err(format!("Unknown software: {}", software)),
+    };
+
+    // 发送安装完成或错误事件
+    match &result {
+        Ok(install_result) if install_result.success => {
+            let _ = app.emit("install-complete", serde_json::json!({
+                "software": software,
+                "message": &install_result.message,
+                "i18nKey": &install_result.i18n_key,
+            }));
+        }
+        Ok(install_result) => {
+            // 安装被取消或其他非成功情况
+            let _ = app.emit("install-error", serde_json::json!({
+                "software": software,
+                "message": &install_result.message,
+                "i18nKey": &install_result.i18n_key,
+            }));
+        }
+        Err(error_msg) => {
+            let _ = app.emit("install-error", serde_json::json!({
+                "software": software,
+                "message": error_msg,
+            }));
+        }
     }
+
+    result
 }
 
 /// 取消安装
@@ -613,28 +640,59 @@ where
 {
     let mut results = Vec::new();
 
+    // 辅助函数:为每个子软件发送安装完成/错误事件
+    let emit_sub_result = |software: &str, result: &Result<InstallResult, String>| {
+        match result {
+            Ok(install_result) if install_result.success => {
+                let _ = app.emit("install-complete", serde_json::json!({
+                    "software": software,
+                    "message": &install_result.message,
+                    "i18nKey": &install_result.i18n_key,
+                }));
+            }
+            Ok(install_result) => {
+                let _ = app.emit("install-error", serde_json::json!({
+                    "software": software,
+                    "message": &install_result.message,
+                    "i18nKey": &install_result.i18n_key,
+                }));
+            }
+            Err(error_msg) => {
+                let _ = app.emit("install-error", serde_json::json!({
+                    "software": software,
+                    "message": error_msg,
+                }));
+            }
+        }
+    };
+
     if options.install_nodejs.unwrap_or(false) {
         let result = install_nodejs(app, state, options, emit_status, is_cancelled).await;
+        emit_sub_result("nodejs", &result);
         results.push(("nodejs", result));
     }
 
     if options.install_pnpm.unwrap_or(false) {
         let result = install_pnpm(app, state, emit_status, is_cancelled).await;
+        emit_sub_result("pnpm", &result);
         results.push(("pnpm", result));
     }
 
     if options.install_vscode.unwrap_or(false) {
         let result = install_vscode(app, state, options, emit_status, is_cancelled).await;
+        emit_sub_result("vscode", &result);
         results.push(("vscode", result));
     }
 
     if options.install_git.unwrap_or(false) {
         let result = install_git(app, state, options, emit_status, is_cancelled).await;
+        emit_sub_result("git", &result);
         results.push(("git", result));
     }
 
     if options.install_claude_code.unwrap_or(false) {
         let result = install_claude_code_software(app, state, emit_status, is_cancelled).await;
+        emit_sub_result("claudeCode", &result);
         results.push(("claudeCode", result));
     }
 

+ 21 - 1
src/i18n/en-US.ts

@@ -113,6 +113,7 @@ export default {
     start: 'Install',
     startAll: 'Start Installation',
     installing: 'Installing...',
+    downloading: 'Downloading...',
     complete: 'Installation Complete',
     failed: 'Installation Failed',
     cancelled: 'Installation Cancelled',
@@ -126,7 +127,26 @@ export default {
     noSelectionHint: 'Please select software to install',
     customPath: 'Install Path',
     customPathPlaceholder: 'Leave empty for default path',
-    browse: 'Browse...'
+    browse: 'Browse...',
+    success: 'Installation successful',
+    nodejs: {
+      success: 'Node.js installed successfully'
+    },
+    pnpm: {
+      success: 'pnpm installed successfully'
+    },
+    vscode: {
+      success: 'VS Code installed successfully'
+    },
+    git: {
+      success: 'Git installed successfully'
+    },
+    claudeCode: {
+      success: 'Claude Code installed successfully'
+    },
+    all: {
+      success: 'All software installed successfully'
+    }
   },
   settings: {
     title: 'Settings',

+ 21 - 1
src/i18n/zh-CN.ts

@@ -113,6 +113,7 @@ export default {
     start: '开始安装',
     startAll: '开始一键安装',
     installing: '安装中...',
+    downloading: '正在下载...',
     complete: '安装完成',
     failed: '安装失败',
     cancelled: '安装已取消',
@@ -126,7 +127,26 @@ export default {
     noSelectionHint: '请勾选要安装的软件',
     customPath: '安装路径',
     customPathPlaceholder: '留空使用默认路径',
-    browse: '浏览...'
+    browse: '浏览...',
+    success: '安装成功',
+    nodejs: {
+      success: 'Node.js 安装成功'
+    },
+    pnpm: {
+      success: 'pnpm 安装成功'
+    },
+    vscode: {
+      success: 'VS Code 安装成功'
+    },
+    git: {
+      success: 'Git 安装成功'
+    },
+    claudeCode: {
+      success: 'Claude Code 安装成功'
+    },
+    all: {
+      success: '全部软件安装成功'
+    }
   },
   settings: {
     title: '设置',