From 91ab92af3f6ddb177a616b26b07b77754382b9c0 Mon Sep 17 00:00:00 2001 From: zhbaor Date: Thu, 10 Oct 2024 10:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 31 ++++++++++++++++--------------- ui/src/components/FloatButton.vue | 11 ++++++++++- ui/src/pages/Fix.vue | 3 +++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 8f28c13..6b4f6c9 100644 --- a/main.py +++ b/main.py @@ -79,24 +79,25 @@ class Api: if callable(command): command = command() custom_event(command + "\n") - with Popen( - command, - stdout=PIPE, - stderr=STDOUT, - shell=True, - bufsize=1, - text=True, - cwd=cwd, - encoding="utf-8", - ) as p: - for line in p.stdout: - custom_event(line) + try: + with Popen( + command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0 + ) as p: + for data in p.stdout: + try: + text = data.decode("utf-8") + except Exception: + text = data.decode("gbk") + custom_event(text) + if p.returncode == 0: + return "success" + except Exception as e: + custom_event(str(e)) + return "failed" window = webview.create_window( - f"mower-ng launcher {version}", - "ui/dist/index.html", - js_api=Api(), + f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api() ) webview.start() diff --git a/ui/src/components/FloatButton.vue b/ui/src/components/FloatButton.vue index 4509c77..06f16c1 100644 --- a/ui/src/components/FloatButton.vue +++ b/ui/src/components/FloatButton.vue @@ -17,7 +17,16 @@ async function start() { current_step.value = i + 1 current_state.value = 'process' for (const cmd of step.command) { - await pywebview.api.run(cmd, step.cwd) + if ((await pywebview.api.run(cmd, step.cwd)) == 'failed') { + current_state.value = 'error' + running.value = false + notification['error']({ + content: '错误', + meta: '命令运行失败', + duration: 3000 + }) + return + } } } current_state.value = 'finish' diff --git a/ui/src/pages/Fix.vue b/ui/src/pages/Fix.vue index 019c9d5..1f97086 100644 --- a/ui/src/pages/Fix.vue +++ b/ui/src/pages/Fix.vue @@ -1,6 +1,8 @@