diff --git a/launcher/constants.py b/launcher/constants.py index da1c637..213679a 100644 --- a/launcher/constants.py +++ b/launcher/constants.py @@ -11,6 +11,8 @@ upgrade_script_name = "upgrade.bat" # 获取最新版本发布信息 get_new_version_url = "https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest" +# 下载新版本压缩包名 +file_name = "launcher.7z" # 下载地址 download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z" diff --git a/launcher/webview/api.py b/launcher/webview/api.py index a869430..bee397a 100644 --- a/launcher/webview/api.py +++ b/launcher/webview/api.py @@ -1,7 +1,6 @@ import io import os import subprocess -import threading from _winapi import CREATE_NO_WINDOW from pathlib import Path from shutil import rmtree @@ -11,7 +10,7 @@ import requests from launcher import config from launcher.constants import download_git_url, download_python_url, get_new_version_url, upgrade_script_name, \ - mirror_list + mirror_list, file_name from launcher.file.download import init_download, download_file from launcher.file.extract import extract_7z_file from launcher.file.utils import ensure_directory_exists, check_command_path @@ -30,7 +29,7 @@ command_list = { "reset": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=200 reset --hard origin/{config.conf.branch}", "pip_tools_install": lambda: f"..\\python\\Scripts\\pip install --no-cache-dir -i {mirror_list[config.conf.mirror]} pip-tools --no-warn-script-location", "pip_sync": lambda: f"..\\python\\Scripts\\pip-sync -i {mirror_list[config.conf.mirror]} requirements.txt", - "webview": "start ..\\python\\pythonw webview_ui.py", + "webview": "..\\python\\pythonw webview_ui.py", "manager": "start ..\\python\\pythonw manager.py", } @@ -49,24 +48,17 @@ def parse_stderr(stderr_output): return "未定义的错误" -def read_stream(stream, log_type, output_list=None): - def process_lines(text_io): - for line in iter(text_io.readline, ''): - text = line.rstrip('\n').strip() - custom_event(log_type, text) - if output_list is not None: - output_list.append(text) - - detected_encoding = 'utf-8' - text_io = io.TextIOWrapper(stream, encoding=detected_encoding, errors='replace') - try: - process_lines(text_io) - except UnicodeDecodeError: - stream.seek(0) # 重新将流指针重置到开头 - text_io = io.TextIOWrapper(stream, encoding='gbk', errors='replace') - process_lines(text_io) - finally: - text_io.close() +def check_command_end(command_key, output): + end_keywords = { + "webview": {"WebSocket客户端建立连接": "mower_ng已成功运行"} + } + if command_key in end_keywords: + keywords = end_keywords[command_key] + for keyword in keywords: + if keyword in output: + custom_event(LogType.info, keywords[keyword]) + return True + return False class Api: @@ -91,8 +83,6 @@ class Api: # 更新启动器本身 def update_self(self, download_url): logger.info(f"开始更新启动器 {download_url}") - file_name = os.path.basename(download_url) - file_name = "launcher.7z" current_path = os.getcwd() download_tmp_folder = os.path.join(current_path, "download_tmp") # 确保 download_tmp 文件夹存在 @@ -144,8 +134,8 @@ class Api: except Exception as e: return repr(e) - def run(self, command, cwd=None): - command = command_list[command] + def run(self, command_key, cwd=None): + command = command_list[command_key] if callable(command): command = command() if callable(command): @@ -161,18 +151,28 @@ class Api: try: stdout_stderr = [] with subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cwd, bufsize=0, + command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=cwd, bufsize=0, universal_newlines=False ) as p: - stdout_thread = threading.Thread(target=read_stream, args=(p.stdout, LogType.command_out)) - stderr_thread = threading.Thread(target=read_stream, - args=(p.stderr, LogType.command_out, stdout_stderr)) + def process_lines(text_io): + for line in iter(text_io.readline, ''): + text = line.rstrip('\n').strip() + custom_event(LogType.command_out, text) + if stdout_stderr is not None: + stdout_stderr.append(text) + if check_command_end(command_key, text): + break - stdout_thread.start() - stderr_thread.start() - - stdout_thread.join() - stderr_thread.join() + detected_encoding = 'utf-8' + text_io = io.TextIOWrapper(p.stdout, encoding=detected_encoding, errors='replace') + try: + process_lines(text_io) + except UnicodeDecodeError: + p.stdout.seek(0) # 重新将流指针重置到开头 + text_io = io.TextIOWrapper(p.stdout, encoding='gbk', errors='replace') + process_lines(text_io) + finally: + text_io.close() if p.returncode == 0: return "success" diff --git a/ui/src/pages/Launch.vue b/ui/src/pages/Launch.vue index 23409c0..c84940c 100644 --- a/ui/src/pages/Launch.vue +++ b/ui/src/pages/Launch.vue @@ -1,4 +1,8 @@ @@ -34,4 +31,4 @@ function manager() { width: 120px; height: 48px; } - + \ No newline at end of file diff --git a/ui/src/pages/Settings.vue b/ui/src/pages/Settings.vue index 120ff2c..5428726 100644 --- a/ui/src/pages/Settings.vue +++ b/ui/src/pages/Settings.vue @@ -91,5 +91,6 @@ async function check_update() { + diff --git a/ui/src/stores/config.js b/ui/src/stores/config.js index f20625c..e33269a 100644 --- a/ui/src/stores/config.js +++ b/ui/src/stores/config.js @@ -3,10 +3,12 @@ import { defineStore } from 'pinia' export const useConfigStore = defineStore('config', () => { class Config { constructor(conf) { + // 整体 Total this.page = conf.page + this.is_already_show_doc = conf.is_already_show_doc + // 更新代码 UpdatePart this.branch = conf.branch this.mirror = conf.mirror - this.is_already_show_doc = conf.is_already_show_doc } }