From 7676441678ed1b4a8126a2be2f1e9b07a5dcd730 Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 29 Apr 2022 17:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 32 +++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index f5cc522..afd0c26 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -109,8 +109,8 @@ export default { hideWindow && utools.hideMainWindow(); // 对于本身就没有输出的命令,无法确认命令是否执行完成,所以干脆提前退出插件 // 弊端就是如果勾选了隐藏后台就完全退出的话,会造成命令直接中断 - let quitBeforeShowResult = this.fromUtools && outPlugin; - quitBeforeShowResult && + let earlyExit = this.fromUtools && outPlugin; + earlyExit && setTimeout(() => { utools.outPlugin(); }, 500); @@ -118,14 +118,7 @@ export default { window.runCodeInSandbox( currentCommand.cmd, (stdout, stderr) => { - if (stderr) { - return quitBeforeShowResult - ? alert(stderr) - : this.showRunResult(stderr, false, action); - } - outPlugin - ? action(stdout.toString()) - : this.showRunResult(stdout, true); + this.handleResult(stdout, stderr, { outPlugin, action, earlyExit }); }, { enterData: this.$root.enterData } ); @@ -143,14 +136,7 @@ export default { option, currentCommand.output === "terminal", (stdout, stderr) => { - if (stderr) { - return quitBeforeShowResult - ? alert(stderr) - : this.showRunResult(stderr, false, action); - } - outPlugin - ? action(stdout.toString()) - : this.showRunResult(stdout, true); + this.handleResult(stdout, stderr, { outPlugin, action, earlyExit }); } ); // ctrl c 终止 @@ -235,6 +221,16 @@ export default { payload: await commandTypes[type]?.tempPayload?.(), }; }, + handleResult(stdout, stderr, options) { + if (stderr) { + return options.earlyExit + ? alert(stderr) + : this.showRunResult(stderr, false); + } + options.outPlugin + ? options.action(stdout.toString()) + : this.showRunResult(stdout, true); + }, // 显示运行结果 showRunResult(content, isSuccess) { this.isResultShow = true;