美化+命令修复

This commit is contained in:
zhbaor 2024-09-23 19:42:56 +08:00
parent 32496af392
commit ec44c5c9ad
8 changed files with 35 additions and 24 deletions

17
main.py
View file

@ -16,13 +16,14 @@ except Exception:
}
def custom_event(name, data):
data = json.dumps({name: data})
def custom_event(data):
data = json.dumps({"log": data})
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
window.evaluate_js(js)
command_list = {
"lfs": "git\\bin\\git lfs install",
"ensurepip": "python\\python -m ensurepip --default-pip --no-warn-script-location",
"clone": "git\\bin\\git clone https://git-cf.zhaozuohong.vip/mower-ng/mower-ng.git --branch slow",
"fetch": "..\\git\\bin\\git fetch",
@ -30,6 +31,7 @@ command_list = {
"switch_slow": "..\\git\\bin\\git switch -f slow",
"reset_fast": "..\\git\\bin\\git reset --hard origin/fast",
"reset_slow": "..\\git\\bin\\git reset --hard origin/slow",
"pip_install": "..\\python\\Scripts\\pip install -i https://mirror.sjtu.edu.cn/pypi/web/simple -r requirements.txt --no-warn-script-location",
"webview": "start ..\\python\\pythonw webview_ui.py",
"manager": "start ..\\python\\pythonw manager.py",
}
@ -49,8 +51,10 @@ class Api:
config["page"] = page
def run(self, command, cwd=None):
command = command_list[command]
custom_event(command + "\n")
with Popen(
command_list[command],
command,
stdout=PIPE,
stderr=STDOUT,
shell=True,
@ -59,11 +63,12 @@ class Api:
cwd=cwd,
) as p:
for line in p.stdout:
custom_event("log", line)
custom_event(line)
window = webview.create_window("mower-ng launcher", "dist/index.html", js_api=Api())
webview.start()
# window = webview.create_window("mower-ng launcher", "dist/index.html", js_api=Api())
window = webview.create_window("mower-ng launcher", "http://localhost:5173/", js_api=Api())
webview.start(debug=True)
with config_path.open("w") as f:
json.dump(config, f)