|
|
@@ -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));
|
|
|
}
|
|
|
|