From 5c57212a9079c2b791015f7a6474734cd72772c8 Mon Sep 17 00:00:00 2001 From: codetypes Date: Tue, 16 Jul 2024 17:23:10 +0800 Subject: [PATCH] prompt batch error --- public/locales/en.json | 2 ++ public/locales/zh.json | 2 ++ src/contexts/workspace-context.ts | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/public/locales/en.json b/public/locales/en.json index 2e2a902..c2560eb 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -3,6 +3,8 @@ "actuaSize": "Actual Size", "build": "Build", "batch": "Batch Script", + "batchCompleted": "Batch completed", + "batchFailed": "Batch failed, more information can be found in the console.", "buildCompleted": "Build completed", "buildFailed": "Build failed, more information can be found in the console.", "cancel": "Cancel", diff --git a/public/locales/zh.json b/public/locales/zh.json index 4061656..a2a84f8 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -3,6 +3,8 @@ "actualSize": "实际大小", "build": "构建", "batch": "批处理脚本", + "batchCompleted": "批处理完成", + "batchFailed": "批处理出现错误,详情请查看控制台!", "buildCompleted": "构建完成", "buildFailed": "构建出现错误,详情请查看控制台!", "cancel": "取消", diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index 02178be..c1a8a5a 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -310,6 +310,7 @@ export const useWorkspace = create((set, get) => ({ filters: [{ name: "Javascript", extensions: ["js"] }], })?.[0]; if (scriptPath) { + let hasError = false; try { console.log("run script", scriptPath); const str = fs.readFileSync(scriptPath, "utf8"); @@ -332,8 +333,14 @@ export const useWorkspace = create((set, get) => ({ } }); } catch (error) { + hasError = true; console.error(error); } + if (hasError) { + message.error(i18n.t("batchFailed")); + } else { + message.success(i18n.t("batchCompleted")); + } } },