From ec44c5c9addcac6e7f25dc3ff68cd84db6bc5aa7 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Mon, 23 Sep 2024 19:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=8C=96+=E5=91=BD=E4=BB=A4=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 +++++++++++------ ui/index.html | 2 +- ui/src/App.vue | 4 +--- ui/src/components/FloatButton.vue | 4 ++-- ui/src/components/LogComponent.vue | 8 +++++++- ui/src/pages/Init.vue | 6 +++--- ui/src/pages/Launch.vue | 10 +++++++--- ui/src/pages/Update.vue | 8 +++----- 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index 9889397..fbbe7ad 100644 --- a/main.py +++ b/main.py @@ -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.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) diff --git a/ui/index.html b/ui/index.html index bd5e85d..e631329 100644 --- a/ui/index.html +++ b/ui/index.html @@ -6,7 +6,7 @@ Vite App - +
diff --git a/ui/src/App.vue b/ui/src/App.vue index 6550023..d7a9bbf 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -8,8 +8,6 @@ const loading = ref(true) const page = ref(null) function load_config() { - console.log('load_config') - console.log(pywebview) pywebview.api.get_page().then((value) => { page.value = value loading.value = false @@ -50,7 +48,7 @@ provide('steps', steps)