报错处理

This commit is contained in:
zhbaor 2024-10-10 10:48:01 +08:00
parent 585f777832
commit 91ab92af3f
3 changed files with 29 additions and 16 deletions

31
main.py
View file

@ -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()