From c94d6d5494e2a550990260fb5e9fa20a42547e32 Mon Sep 17 00:00:00 2001 From: li-xiaochen <397721316@qq.com> Date: Sun, 23 Feb 2025 20:09:32 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9A=E6=89=93=E5=8C=85=E5=90=8E=E8=BF=90=E8=A1=8C=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E6=97=B6=E7=BC=96=E7=A0=81=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher/webview/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/webview/api.py b/launcher/webview/api.py index b24ab1d..5842e9f 100644 --- a/launcher/webview/api.py +++ b/launcher/webview/api.py @@ -42,7 +42,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": lambda instance_path="": f'..\\python\\pythonw webview_ui.py "{instance_path}"', + "webview": lambda instance_path="": f'..\\python\\pythonw -X utf8 webview_ui.py "{instance_path}"', "open_folder": lambda folder_path: f"explorer {folder_path}", } From f5011e00513e0400a44d3a3c18472c2a87c6324e Mon Sep 17 00:00:00 2001 From: li-xiaochen <397721316@qq.com> Date: Sun, 23 Feb 2025 20:28:31 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9A=E6=89=93=E5=BC=80=E5=AE=9E=E4=BE=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E6=97=B6=E5=BC=82=E5=B8=B8=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher/webview/api.py | 8 +++++++- ui/src/pages/Launch.vue | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/launcher/webview/api.py b/launcher/webview/api.py index 5842e9f..227f82e 100644 --- a/launcher/webview/api.py +++ b/launcher/webview/api.py @@ -43,7 +43,6 @@ command_list = { "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": lambda instance_path="": f'..\\python\\pythonw -X utf8 webview_ui.py "{instance_path}"', - "open_folder": lambda folder_path: f"explorer {folder_path}", } @@ -252,3 +251,10 @@ class Api: def migrate_instances_config(self): """迁移多开配置""" return manager.migrate_instances_config() + + def open_folder(self, path): + if not os.path.exists(path): + custom_event(LogType.error, f"路径不存在:{path}") + else: + os.startfile(path) + custom_event(LogType.info, f"成功打开文件夹:{path}") diff --git a/ui/src/pages/Launch.vue b/ui/src/pages/Launch.vue index 3c15f37..faaacff 100644 --- a/ui/src/pages/Launch.vue +++ b/ui/src/pages/Launch.vue @@ -62,7 +62,7 @@ function end_update_instance_name() { update_instance_name_index.value = null } function open_folder(path) { - pywebview.api.run('open_folder', null, { folder_path: path }) + pywebview.api.open_folder(path) } function start_instance(instance) { pywebview.api.run('webview', 'mower-ng', { From 501259b420c6994c3502cfefa930b4926ffa1b54 Mon Sep 17 00:00:00 2001 From: li-xiaochen <397721316@qq.com> Date: Sun, 23 Feb 2025 21:00:43 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=8F=91=E5=B8=83v0.6.1=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher/sys_config/config_dist.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/sys_config/config_dist.json b/launcher/sys_config/config_dist.json index 9c9c5fd..2649876 100644 --- a/launcher/sys_config/config_dist.json +++ b/launcher/sys_config/config_dist.json @@ -1,5 +1,5 @@ { - "version": "v0.6", + "version": "v0.6.1", "url": "ui/dist/index.html", "log_level": "INFO", "debug": false From de2c2af2bd8abda93167a680bd2b0f32b9b48ffc Mon Sep 17 00:00:00 2001 From: li-xiaochen <397721316@qq.com> Date: Sat, 8 Mar 2025 11:28:22 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=E6=B7=BB=E5=8A=A0zhaozuohong.vip=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher/config/conf.py | 22 ++++++++++++++- launcher/constants.py | 7 +++-- launcher/utils.py | 12 +++++++++ launcher/webview/api.py | 37 ++++++++++++++++++++++---- ui/src/components/BaseMirrorOption.vue | 30 +++++++++++++++++++++ ui/src/pages/Init.vue | 5 ++++ ui/src/pages/Settings.vue | 13 ++++++--- ui/src/pages/Update.vue | 9 ++++--- ui/src/stores/config.js | 2 ++ 9 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 launcher/utils.py create mode 100644 ui/src/components/BaseMirrorOption.vue diff --git a/launcher/config/conf.py b/launcher/config/conf.py index a5df264..cfeca5c 100644 --- a/launcher/config/conf.py +++ b/launcher/config/conf.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Literal, get_args, get_origin from pydantic import BaseModel, model_validator from pydantic_core import PydanticUndefined @@ -15,6 +15,18 @@ class ConfModel(BaseModel): data[name] = expected_type else: data[name] = field.default + value = data[name] + + # 检查 Literal 类型并修正 + if get_origin(expected_type) is Literal: + valid_literals = get_args(expected_type) + if value not in valid_literals: + # 修正为默认值 + data[name] = ( + field.default + if field.default is not PydanticUndefined + else None + ) return data @@ -55,9 +67,17 @@ class LaunchPart(ConfModel): is_show_log: bool = False +class OtherPart(ConfModel): + """其他配置""" + + # xx.zhaozuohong.vip镜像 (访问xx.zhaozuohong.vip url时,0=原路径 1=在.zhaozuohong.vip前添加-cf前缀) + base_mirror: Literal["0", "1"] = "0" + + class Conf( Total, UpdatePart, LaunchPart, + OtherPart, ): pass diff --git a/launcher/constants.py b/launcher/constants.py index 3e519e2..507139e 100644 --- a/launcher/constants.py +++ b/launcher/constants.py @@ -8,18 +8,21 @@ constants.py update_tmp_folder = "download_tmp" # 更新脚本名 upgrade_script_name = "upgrade.bat" +# 下载新版本压缩包名 +file_name = "launcher.7z" # 获取最新版本发布信息 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" download_python_url = "https://list.zhaozuohong.vip/mower-ng/python.7z" +# mower-ng git链接 +mower_ng_git_url = "https://git.zhaozuohong.vip/mower-ng/mower-ng.git" + # pip镜像地址 mirror_list = { "pypi": "https://pypi.org/simple", diff --git a/launcher/utils.py b/launcher/utils.py new file mode 100644 index 0000000..bb56ecc --- /dev/null +++ b/launcher/utils.py @@ -0,0 +1,12 @@ +from launcher import config + + +def build_base_url(url: str) -> str: + """ + 构建xx.zhaozuohong.vip,如果配置base_mirror是1,在.zhaozuohong.vip前添加-cf前缀 + :param url: 带有xx.zhaozuohong.vip的url字符串 + :return: 构建完成的url + """ + if config.conf.base_mirror == "1": + url = url.replace(".zhaozuohong.vip", "-cf.zhaozuohong.vip") + return url diff --git a/launcher/webview/api.py b/launcher/webview/api.py index 227f82e..f7769f2 100644 --- a/launcher/webview/api.py +++ b/launcher/webview/api.py @@ -3,6 +3,7 @@ import os import shutil import subprocess import threading +import time from _winapi import CREATE_NO_WINDOW from pathlib import Path from shutil import rmtree @@ -20,6 +21,7 @@ from launcher.constants import ( mirror_list, file_name, instances_folder_name, + mower_ng_git_url, ) from launcher.file.download import init_download, download_file from launcher.file.extract import extract_7z_file @@ -27,17 +29,22 @@ from launcher.file.utils import ensure_directory_exists, check_command_path from launcher.instances import manager from launcher.log import logger from launcher.sys_config import sys_config +from launcher.utils import build_base_url from launcher.webview.events import custom_event, LogType command_list = { - "download_git": lambda: init_download("git", download_git_url, os.getcwd()), + "download_git": lambda: init_download( + "git", build_base_url(download_git_url), os.getcwd() + ), "download_python": lambda: init_download( - "python", download_python_url, os.getcwd() + "python", build_base_url(download_python_url), os.getcwd() ), "lfs": "git\\bin\\git lfs install", "ensurepip": "python\\python -m ensurepip --default-pip", - "clone": "git\\bin\\git -c lfs.concurrenttransfers=100 clone https://git.zhaozuohong.vip/mower-ng/mower-ng.git --branch slow", - "fetch": lambda: f"..\\git\\bin\\git fetch origin {config.conf.branch} --progress", + "clone": lambda: f"git\\bin\\git -c lfs.concurrenttransfers=100 clone {build_base_url(mower_ng_git_url)} --branch slow", + "set_remote": lambda: f"..\\git\\bin\\git remote set-url origin {build_base_url(mower_ng_git_url)}", + "set_lfs": lambda: f"..\\git\\bin\\git config lfs.url {build_base_url(mower_ng_git_url)}/info/lfs", + "fetch": lambda: f"..\\git\\bin\\git fetch {build_base_url(mower_ng_git_url)} {config.conf.branch} --progress", "switch": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=100 switch -f {config.conf.branch} --progress", "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", @@ -86,11 +93,12 @@ class Api: def get_new_version(self): logger.info("获取最新版本号") - response = requests.get(get_new_version_url) + response = requests.get(build_base_url(get_new_version_url)) return response.json() # 更新启动器本身 def update_self(self, download_url): + download_url = build_base_url(download_url) logger.info(f"开始更新启动器 {download_url}") current_path = os.getcwd() download_tmp_folder = os.path.join(current_path, "download_tmp") @@ -258,3 +266,22 @@ class Api: else: os.startfile(path) custom_event(LogType.info, f"成功打开文件夹:{path}") + + def test_base_url_connect(self): + url = build_base_url(get_new_version_url) + custom_event(LogType.info, f"开始测试URL连接:{url}") + try: + start_time = time.time() + response = requests.get(url) + end_time = time.time() + if response.status_code == 200: + elapsed_time_ms = (end_time - start_time) * 1000 + custom_event( + LogType.info, f"测试成功,响应时间为 {elapsed_time_ms:.2f} 毫秒" + ) + else: + custom_event( + LogType.error, f"测试失败: HTTP状态码 {response.status_code}" + ) + except requests.exceptions.RequestException as e: + custom_event(LogType.error, f"发生错误: {e}") diff --git a/ui/src/components/BaseMirrorOption.vue b/ui/src/components/BaseMirrorOption.vue new file mode 100644 index 0000000..8d1037d --- /dev/null +++ b/ui/src/components/BaseMirrorOption.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/ui/src/pages/Init.vue b/ui/src/pages/Init.vue index ac577ad..0120bfe 100644 --- a/ui/src/pages/Init.vue +++ b/ui/src/pages/Init.vue @@ -1,4 +1,6 @@