报错处理
This commit is contained in:
parent
585f777832
commit
91ab92af3f
3 changed files with 29 additions and 16 deletions
27
main.py
27
main.py
|
@ -79,24 +79,25 @@ class Api:
|
||||||
if callable(command):
|
if callable(command):
|
||||||
command = command()
|
command = command()
|
||||||
custom_event(command + "\n")
|
custom_event(command + "\n")
|
||||||
|
try:
|
||||||
with Popen(
|
with Popen(
|
||||||
command,
|
command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0
|
||||||
stdout=PIPE,
|
|
||||||
stderr=STDOUT,
|
|
||||||
shell=True,
|
|
||||||
bufsize=1,
|
|
||||||
text=True,
|
|
||||||
cwd=cwd,
|
|
||||||
encoding="utf-8",
|
|
||||||
) as p:
|
) as p:
|
||||||
for line in p.stdout:
|
for data in p.stdout:
|
||||||
custom_event(line)
|
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(
|
window = webview.create_window(
|
||||||
f"mower-ng launcher {version}",
|
f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api()
|
||||||
"ui/dist/index.html",
|
|
||||||
js_api=Api(),
|
|
||||||
)
|
)
|
||||||
webview.start()
|
webview.start()
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,16 @@ async function start() {
|
||||||
current_step.value = i + 1
|
current_step.value = i + 1
|
||||||
current_state.value = 'process'
|
current_state.value = 'process'
|
||||||
for (const cmd of step.command) {
|
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'
|
current_state.value = 'finish'
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
const running = inject('running')
|
||||||
const notification = useNotification()
|
const notification = useNotification()
|
||||||
async function rm_site_packages() {
|
async function rm_site_packages() {
|
||||||
|
running.value = true
|
||||||
notification['info']({
|
notification['info']({
|
||||||
content: '提示',
|
content: '提示',
|
||||||
meta: '开始移除site-packages',
|
meta: '开始移除site-packages',
|
||||||
|
@ -12,6 +14,7 @@ async function rm_site_packages() {
|
||||||
meta: response,
|
meta: response,
|
||||||
duration: 3000
|
duration: 3000
|
||||||
})
|
})
|
||||||
|
running.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue