Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
06fab427aa | |||
e3c2627fc5 | |||
e4b93b94b1 | |||
6e235a28c1 | |||
e3457c1081 | |||
5576f8de39 | |||
de2c2af2bd | |||
501259b420 | |||
f5011e0051 | |||
c94d6d5494 | |||
4153164c49 | |||
dc32d7e53e | |||
942d93417b | |||
25f9915fcc | |||
cae312a272 | |||
9295d9f2cf |
28 changed files with 893 additions and 165 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
/conf.yml
|
/conf.yml
|
||||||
/conf.json
|
/conf.json
|
||||||
/dist
|
/dist
|
||||||
|
/instances/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -66,7 +67,6 @@ db.sqlite3
|
||||||
db.sqlite3-journal
|
db.sqlite3-journal
|
||||||
|
|
||||||
# Flask stuff:
|
# Flask stuff:
|
||||||
instance/
|
|
||||||
.webassets-cache
|
.webassets-cache
|
||||||
|
|
||||||
# Scrapy stuff:
|
# Scrapy stuff:
|
||||||
|
|
|
@ -9,8 +9,7 @@ mimetypes.add_type("text/html", ".html")
|
||||||
mimetypes.add_type("text/css", ".css")
|
mimetypes.add_type("text/css", ".css")
|
||||||
mimetypes.add_type("application/javascript", ".js")
|
mimetypes.add_type("application/javascript", ".js")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
|
|
||||||
# 如果当前路径存在临时文件夹,则删除
|
# 如果当前路径存在临时文件夹,则删除
|
||||||
if Path(update_tmp_folder).exists():
|
if Path(update_tmp_folder).exists():
|
||||||
shutil.rmtree(update_tmp_folder)
|
shutil.rmtree(update_tmp_folder)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import List, Literal, get_args, get_origin
|
||||||
|
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
from pydantic_core import PydanticUndefined
|
from pydantic_core import PydanticUndefined
|
||||||
|
|
||||||
|
@ -7,16 +9,30 @@ class ConfModel(BaseModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def nested_defaults(cls, data):
|
def nested_defaults(cls, data):
|
||||||
for name, field in cls.model_fields.items():
|
for name, field in cls.model_fields.items():
|
||||||
|
expected_type = field.annotation
|
||||||
if name not in data:
|
if name not in data:
|
||||||
if field.default is PydanticUndefined:
|
if field.default is PydanticUndefined:
|
||||||
data[name] = field.annotation()
|
data[name] = expected_type
|
||||||
else:
|
else:
|
||||||
data[name] = field.default
|
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
|
return data
|
||||||
|
|
||||||
|
|
||||||
class Total(ConfModel):
|
class Total(ConfModel):
|
||||||
"""整体"""
|
"""整体"""
|
||||||
|
|
||||||
# 所在页面
|
# 所在页面
|
||||||
page: str = "init"
|
page: str = "init"
|
||||||
# 是否已展示帮助文档
|
# 是否已展示帮助文档
|
||||||
|
@ -25,14 +41,43 @@ class Total(ConfModel):
|
||||||
|
|
||||||
class UpdatePart(ConfModel):
|
class UpdatePart(ConfModel):
|
||||||
"""更新代码"""
|
"""更新代码"""
|
||||||
|
|
||||||
# mower-ng 代码分支
|
# mower-ng 代码分支
|
||||||
branch: str = "slow"
|
branch: str = "slow"
|
||||||
# PyPI 仓库镜像
|
# PyPI 仓库镜像
|
||||||
mirror: str = "aliyun"
|
mirror: str = "aliyun"
|
||||||
|
|
||||||
|
|
||||||
|
class LaunchPart(ConfModel):
|
||||||
|
"""启动程序"""
|
||||||
|
|
||||||
|
class Instance(ConfModel):
|
||||||
|
"""实例"""
|
||||||
|
|
||||||
|
# 是否选中
|
||||||
|
checked: bool = False
|
||||||
|
# 实例名
|
||||||
|
name: str = ""
|
||||||
|
# 实例路径
|
||||||
|
path: str = ""
|
||||||
|
|
||||||
|
# 实例列表
|
||||||
|
instances: List[Instance] = []
|
||||||
|
# 是否展示日志窗口
|
||||||
|
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(
|
class Conf(
|
||||||
Total,
|
Total,
|
||||||
UpdatePart,
|
UpdatePart,
|
||||||
|
LaunchPart,
|
||||||
|
OtherPart,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -8,14 +8,21 @@ constants.py
|
||||||
update_tmp_folder = "download_tmp"
|
update_tmp_folder = "download_tmp"
|
||||||
# 更新脚本名
|
# 更新脚本名
|
||||||
upgrade_script_name = "upgrade.bat"
|
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"
|
get_new_version_url = (
|
||||||
|
"https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
||||||
|
)
|
||||||
|
|
||||||
# 下载地址
|
# 下载地址
|
||||||
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
||||||
download_python_url = "https://list.zhaozuohong.vip/mower-ng/python.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镜像地址
|
# pip镜像地址
|
||||||
mirror_list = {
|
mirror_list = {
|
||||||
"pypi": "https://pypi.org/simple",
|
"pypi": "https://pypi.org/simple",
|
||||||
|
@ -23,3 +30,18 @@ mirror_list = {
|
||||||
"tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple",
|
"tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple",
|
||||||
"sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple",
|
"sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 实例文件夹名
|
||||||
|
instances_folder_name = "instances"
|
||||||
|
|
||||||
|
# cli命令
|
||||||
|
cli_command = {
|
||||||
|
"status": "获取mower-ng实例状态",
|
||||||
|
"launch": "启动mower-ng进程",
|
||||||
|
"exit": "停止mower-ng进程",
|
||||||
|
"kill": "强制退出mower-ng进程",
|
||||||
|
"start": "开始运行调度器",
|
||||||
|
"stop": "停止运行调度器",
|
||||||
|
"webui": "在浏览器中打开网页面板",
|
||||||
|
"log": "通过WebSocket获取日志",
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ def download_file(download_name, download_url, destination_folder):
|
||||||
|
|
||||||
response = requests.get(download_url, stream=True)
|
response = requests.get(download_url, stream=True)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
total_size = int(response.headers.get('content-length', 0))
|
total_size = int(response.headers.get("content-length", 0))
|
||||||
downloaded_size = 0
|
downloaded_size = 0
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
last_update_time = time.time() # 记录上次更新时间
|
last_update_time = time.time() # 记录上次更新时间
|
||||||
|
@ -43,7 +43,9 @@ def download_file(download_name, download_url, destination_folder):
|
||||||
else:
|
else:
|
||||||
download_speed = 0
|
download_speed = 0
|
||||||
|
|
||||||
progress_percent = (downloaded_size / total_size) * 100 if total_size != 0 else 0
|
progress_percent = (
|
||||||
|
(downloaded_size / total_size) * 100 if total_size != 0 else 0
|
||||||
|
)
|
||||||
|
|
||||||
# 检查是否需要更新进度信息,每1秒更新一次
|
# 检查是否需要更新进度信息,每1秒更新一次
|
||||||
if current_time - last_update_time >= 1:
|
if current_time - last_update_time >= 1:
|
||||||
|
@ -52,19 +54,25 @@ def download_file(download_name, download_url, destination_folder):
|
||||||
formatted_total_size = format_size(total_size)
|
formatted_total_size = format_size(total_size)
|
||||||
formatted_speed = format_size(download_speed) + "/s"
|
formatted_speed = format_size(download_speed) + "/s"
|
||||||
|
|
||||||
custom_event(LogType.info,
|
custom_event(
|
||||||
f"下载进度: {progress_percent:.2f}% ({formatted_downloaded_size}/{formatted_total_size}), 下载速度: {formatted_speed}")
|
LogType.info,
|
||||||
|
f"下载进度: {progress_percent:.2f}% ({formatted_downloaded_size}/{formatted_total_size}), 下载速度: {formatted_speed}",
|
||||||
|
)
|
||||||
last_update_time = current_time # 更新上次更新时间
|
last_update_time = current_time # 更新上次更新时间
|
||||||
|
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
total_elapsed_time = end_time - start_time
|
total_elapsed_time = end_time - start_time
|
||||||
average_download_speed = downloaded_size / total_elapsed_time if total_elapsed_time != 0 else 0
|
average_download_speed = (
|
||||||
|
downloaded_size / total_elapsed_time if total_elapsed_time != 0 else 0
|
||||||
|
)
|
||||||
# 格式化输出
|
# 格式化输出
|
||||||
formatted_total_elapsed_time = f"{total_elapsed_time:.2f} 秒"
|
formatted_total_elapsed_time = f"{total_elapsed_time:.2f} 秒"
|
||||||
formatted_average_download_speed = format_size(average_download_speed) + "/s"
|
formatted_average_download_speed = format_size(average_download_speed) + "/s"
|
||||||
|
|
||||||
custom_event(LogType.info,
|
custom_event(
|
||||||
f"下载完成: {filename}, 耗时: {formatted_total_elapsed_time}, 下载速度: {formatted_average_download_speed}")
|
LogType.info,
|
||||||
|
f"下载完成: {filename}, 耗时: {formatted_total_elapsed_time}, 下载速度: {formatted_average_download_speed}",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
custom_event(LogType.error, f"下载失败: {response.status_code}")
|
custom_event(LogType.error, f"下载失败: {response.status_code}")
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -37,7 +37,9 @@ class MyExtractCallback(ExtractCallback):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def extract_7z_file(file_name, file_path, destination_folder, delete_after_extract=True):
|
def extract_7z_file(
|
||||||
|
file_name, file_path, destination_folder, delete_after_extract=True
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
解压7z文件到指定文件夹
|
解压7z文件到指定文件夹
|
||||||
:param file_name: 7z文件的名称
|
:param file_name: 7z文件的名称
|
||||||
|
@ -52,14 +54,16 @@ def extract_7z_file(file_name, file_path, destination_folder, delete_after_extra
|
||||||
custom_event(LogType.info, f"开始解压文件: {file_name}")
|
custom_event(LogType.info, f"开始解压文件: {file_name}")
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
with py7zr.SevenZipFile(file_path, mode='r') as z:
|
with py7zr.SevenZipFile(file_path, mode="r") as z:
|
||||||
callback = MyExtractCallback()
|
callback = MyExtractCallback()
|
||||||
z.extractall(path=destination_folder, callback=callback)
|
z.extractall(path=destination_folder, callback=callback)
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
total_elapsed_time = end_time - start_time
|
total_elapsed_time = end_time - start_time
|
||||||
formatted_total_elapsed_time = f"{total_elapsed_time:.2f} 秒"
|
formatted_total_elapsed_time = f"{total_elapsed_time:.2f} 秒"
|
||||||
custom_event(LogType.info,
|
custom_event(
|
||||||
f"解压完成: {file_name}, 总大小: {format_size(callback.total_size)}, 耗时: {formatted_total_elapsed_time}")
|
LogType.info,
|
||||||
|
f"解压完成: {file_name}, 总大小: {format_size(callback.total_size)}, 耗时: {formatted_total_elapsed_time}",
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
custom_event(LogType.error, f"解压失败: {repr(e)}")
|
custom_event(LogType.error, f"解压失败: {repr(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
def format_size(size_bytes):
|
def format_size(size_bytes):
|
||||||
"""格式化文件大小为人类可读的形式"""
|
"""格式化文件大小为人类可读的形式"""
|
||||||
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
||||||
if size_bytes < 1024:
|
if size_bytes < 1024:
|
||||||
return f"{size_bytes:.2f} {unit}"
|
return f"{size_bytes:.2f} {unit}"
|
||||||
size_bytes /= 1024
|
size_bytes /= 1024
|
||||||
|
@ -20,11 +20,14 @@ def check_command_path(command, cwd=None):
|
||||||
"""检查命令路径是否存在exe文件
|
"""检查命令路径是否存在exe文件
|
||||||
:return 是否存在,命令exe文件全路径
|
:return 是否存在,命令exe文件全路径
|
||||||
"""
|
"""
|
||||||
command_path = command.split(" ")[0]
|
command_name = command.split(" ")[0]
|
||||||
if command_path == "start":
|
system_command = ["start", "explorer"]
|
||||||
|
if command_name in system_command:
|
||||||
return True, None
|
return True, None
|
||||||
exec_command_path = os.getcwd()
|
exec_command_path = os.getcwd()
|
||||||
if cwd:
|
if cwd:
|
||||||
exec_command_path = os.path.join(exec_command_path, cwd)
|
exec_command_path = os.path.join(exec_command_path, cwd)
|
||||||
full_command_path = os.path.abspath(os.path.join(exec_command_path, command_path)) + ".exe"
|
full_command_path = (
|
||||||
|
os.path.abspath(os.path.join(exec_command_path, command_name)) + ".exe"
|
||||||
|
)
|
||||||
return os.path.exists(full_command_path), full_command_path
|
return os.path.exists(full_command_path), full_command_path
|
||||||
|
|
0
launcher/instances/__init__.py
Normal file
0
launcher/instances/__init__.py
Normal file
129
launcher/instances/manager.py
Normal file
129
launcher/instances/manager.py
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from launcher import config
|
||||||
|
from launcher.config.conf import LaunchPart
|
||||||
|
from launcher.constants import instances_folder_name
|
||||||
|
from launcher.webview.events import custom_event, LogType
|
||||||
|
|
||||||
|
|
||||||
|
def add_instance():
|
||||||
|
instances_path = os.path.join(os.getcwd(), instances_folder_name)
|
||||||
|
if not os.path.exists(instances_path):
|
||||||
|
os.makedirs(instances_path)
|
||||||
|
instance_folder_name = str(uuid.uuid4())
|
||||||
|
instance_folder_path = os.path.join(instances_path, instance_folder_name)
|
||||||
|
if os.path.exists(instance_folder_path):
|
||||||
|
raise Exception("创建实例目录失败")
|
||||||
|
os.makedirs(instance_folder_path)
|
||||||
|
custom_event(LogType.info, f"创建实例目录成功: {instance_folder_path}")
|
||||||
|
return instance_folder_path
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_instance(source_folder):
|
||||||
|
"""通用配置迁移方法
|
||||||
|
Args:
|
||||||
|
source_folder: 源配置目录路径
|
||||||
|
target_folder: 目标配置目录路径
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if not os.path.exists(source_folder):
|
||||||
|
custom_event(LogType.error, f"源配置目录不存在: {source_folder}")
|
||||||
|
return {"status": False, "message": f"源配置目录不存在{source_folder}"}
|
||||||
|
|
||||||
|
target_folder = add_instance()
|
||||||
|
|
||||||
|
# 需要复制的目录和文件列表
|
||||||
|
copy_items = [("tmp", True), ("conf.yml", False), ("plan.json", False)]
|
||||||
|
|
||||||
|
for item, is_dir in copy_items:
|
||||||
|
src = os.path.join(source_folder, item)
|
||||||
|
dst = os.path.join(target_folder, item)
|
||||||
|
|
||||||
|
if is_dir:
|
||||||
|
if os.path.exists(src):
|
||||||
|
shutil.copytree(src, dst, dirs_exist_ok=True)
|
||||||
|
else:
|
||||||
|
if os.path.exists(src):
|
||||||
|
shutil.copy2(src, dst)
|
||||||
|
|
||||||
|
custom_event(LogType.info, f"{source_folder} 配置成功迁移至 {target_folder}")
|
||||||
|
return {"status": True, "data": target_folder, "message": "配置迁移成功"}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
custom_event(LogType.error, f"配置迁移失败: {str(e)}")
|
||||||
|
return {"status": False, "message": str(e)}
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_instances_config():
|
||||||
|
try:
|
||||||
|
config_path = os.path.join(os.getcwd(), "mower-ng", "instances.json")
|
||||||
|
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
custom_event(LogType.error, f"多开配置文件不存在{config_path}")
|
||||||
|
return {"status": False, "message": "多开配置文件不存在"}
|
||||||
|
|
||||||
|
with open(config_path, "r", encoding="utf-8") as f:
|
||||||
|
instances_data = json.loads(f.read())
|
||||||
|
custom_event(LogType.info, f"读取多开配置: {instances_data}")
|
||||||
|
|
||||||
|
valid_instances = []
|
||||||
|
error_messages = []
|
||||||
|
|
||||||
|
for index, item in enumerate(instances_data, 1):
|
||||||
|
try:
|
||||||
|
# 基础结构验证
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
raise ValueError("配置项必须是字典类型")
|
||||||
|
|
||||||
|
# 必填字段检查
|
||||||
|
required_fields = ["name", "path"]
|
||||||
|
for field in required_fields:
|
||||||
|
if field not in item:
|
||||||
|
raise ValueError(f"缺少必要字段: {field}")
|
||||||
|
|
||||||
|
# 路径有效性验证
|
||||||
|
if not os.path.exists(item["path"]):
|
||||||
|
raise ValueError(f"配置路径不存在{item['path']}")
|
||||||
|
|
||||||
|
# 执行配置迁移
|
||||||
|
migration_result = migrate_instance(item["path"])
|
||||||
|
|
||||||
|
if not migration_result["status"]:
|
||||||
|
raise Exception(f"路径迁移失败: {migration_result['message']}")
|
||||||
|
|
||||||
|
# 转换为实例模型
|
||||||
|
instance = LaunchPart.Instance(
|
||||||
|
name=item["name"].strip(), path=migration_result["data"]
|
||||||
|
)
|
||||||
|
|
||||||
|
valid_instances.append(instance)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error_msg = f"第{index}项: {str(e)}"
|
||||||
|
error_messages.append(error_msg)
|
||||||
|
custom_event(LogType.error, error_msg)
|
||||||
|
|
||||||
|
# 保存有效配置
|
||||||
|
if valid_instances:
|
||||||
|
config.conf.instances.extend(valid_instances)
|
||||||
|
config.save_conf()
|
||||||
|
|
||||||
|
message = f"成功导入{len(valid_instances)}个实例" + (
|
||||||
|
f",存在{len(error_messages)}个错误项" if error_messages else ""
|
||||||
|
)
|
||||||
|
custom_event(LogType.info, message)
|
||||||
|
return {
|
||||||
|
"status": not bool(error_messages),
|
||||||
|
"data": len(valid_instances),
|
||||||
|
"message": message,
|
||||||
|
}
|
||||||
|
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
custom_event(LogType.error, f"JSON解析失败: {str(e)}")
|
||||||
|
return {"status": False, "message": "配置文件格式错误"}
|
||||||
|
except Exception as e:
|
||||||
|
custom_event(LogType.error, f"迁移多开配置失败: {str(e)}")
|
||||||
|
return {"status": False, "message": str(e)}
|
|
@ -9,13 +9,13 @@ from launcher.sys_config import sys_config
|
||||||
|
|
||||||
# 配置日志
|
# 配置日志
|
||||||
def setup_logger():
|
def setup_logger():
|
||||||
log_level = sys_config.get('log_level')
|
log_level = sys_config.get("log_level")
|
||||||
|
|
||||||
logger = logging.getLogger("launcher.log")
|
logger = logging.getLogger("launcher.log")
|
||||||
logger.setLevel(log_level)
|
logger.setLevel(log_level)
|
||||||
|
|
||||||
# 设置标准输出编码为 UTF-8
|
# 设置标准输出编码为 UTF-8
|
||||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
||||||
|
|
||||||
# 控制台输出
|
# 控制台输出
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
|
@ -24,7 +24,7 @@ def setup_logger():
|
||||||
# 文件输出
|
# 文件输出
|
||||||
file_path = os.path.join(os.getcwd(), "launcher.log")
|
file_path = os.path.join(os.getcwd(), "launcher.log")
|
||||||
file_handler = RotatingFileHandler(
|
file_handler = RotatingFileHandler(
|
||||||
file_path, maxBytes=5 * 1024 * 1024, backupCount=3, encoding='utf-8'
|
file_path, maxBytes=5 * 1024 * 1024, backupCount=3, encoding="utf-8"
|
||||||
)
|
)
|
||||||
file_handler.setLevel(logging.INFO)
|
file_handler.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ class SysConfig:
|
||||||
"""
|
"""
|
||||||
读取系统配置文件
|
读取系统配置文件
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 版本
|
# 版本
|
||||||
version: str
|
version: str
|
||||||
# ui路径
|
# ui路径
|
||||||
|
@ -22,25 +23,25 @@ class SysConfig:
|
||||||
self.load_config()
|
self.load_config()
|
||||||
|
|
||||||
def get_config_path(self):
|
def get_config_path(self):
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, "frozen", False):
|
||||||
# logger.error("打包配置")
|
# logger.error("打包配置")
|
||||||
# 如果是打包后的可执行文件
|
# 如果是打包后的可执行文件
|
||||||
base_path = sys._MEIPASS
|
base_path = sys._MEIPASS
|
||||||
config_subdir = 'launcher/sys_config' # 添加子目录
|
config_subdir = "launcher/sys_config" # 添加子目录
|
||||||
config_filename = 'config_dist.json'
|
config_filename = "config_dist.json"
|
||||||
else:
|
else:
|
||||||
# logger.error("本地配置")
|
# logger.error("本地配置")
|
||||||
# 如果是本地开发环境
|
# 如果是本地开发环境
|
||||||
base_path = os.path.dirname(__file__)
|
base_path = os.path.dirname(__file__)
|
||||||
config_subdir = '' # 本地开发环境不需要子目录
|
config_subdir = "" # 本地开发环境不需要子目录
|
||||||
config_filename = 'config_local.json'
|
config_filename = "config_local.json"
|
||||||
|
|
||||||
config_path = os.path.join(base_path, config_subdir, config_filename)
|
config_path = os.path.join(base_path, config_subdir, config_filename)
|
||||||
return config_path
|
return config_path
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
try:
|
try:
|
||||||
with open(self.config_path, 'r', encoding='utf-8') as file:
|
with open(self.config_path, "r", encoding="utf-8") as file:
|
||||||
self.config = json.load(file)
|
self.config = json.load(file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": "v0.5",
|
"version": "v0.7.1",
|
||||||
"url": "ui/dist/index.html",
|
"url": "ui/dist/index.html",
|
||||||
"log_level": "ERROR",
|
"log_level": "INFO",
|
||||||
"debug": false
|
"debug": false
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": "dev",
|
"version": "dev",
|
||||||
"url": "http://localhost:5173/",
|
"url": "http://localhost:5173/",
|
||||||
"log_level": "INFO",
|
"log_level": "DEBUG",
|
||||||
"debug": true
|
"debug": true
|
||||||
}
|
}
|
12
launcher/utils.py
Normal file
12
launcher/utils.py
Normal file
|
@ -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
|
|
@ -8,6 +8,11 @@ window = None
|
||||||
|
|
||||||
def start_webview():
|
def start_webview():
|
||||||
global window
|
global window
|
||||||
window = webview.create_window(f"mower-ng launcher {sys_config.get('version')}", sys_config.get('url'),
|
window = webview.create_window(
|
||||||
js_api=Api())
|
f"mower-ng launcher {sys_config.get('version')}",
|
||||||
webview.start(debug=sys_config.get('debug'))
|
sys_config.get("url"),
|
||||||
|
js_api=Api(),
|
||||||
|
width=850,
|
||||||
|
height=600,
|
||||||
|
)
|
||||||
|
webview.start(debug=sys_config.get("debug"))
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import time
|
||||||
from _winapi import CREATE_NO_WINDOW
|
from _winapi import CREATE_NO_WINDOW
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
@ -10,28 +11,46 @@ from subprocess import Popen
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from launcher import config
|
from launcher import config
|
||||||
from launcher.constants import download_git_url, download_python_url, get_new_version_url, upgrade_script_name, \
|
from launcher.constants import (
|
||||||
mirror_list
|
download_git_url,
|
||||||
|
download_python_url,
|
||||||
|
get_new_version_url,
|
||||||
|
upgrade_script_name,
|
||||||
|
mirror_list,
|
||||||
|
file_name,
|
||||||
|
instances_folder_name,
|
||||||
|
mower_ng_git_url,
|
||||||
|
cli_command,
|
||||||
|
)
|
||||||
from launcher.file.download import init_download, download_file
|
from launcher.file.download import init_download, download_file
|
||||||
from launcher.file.extract import extract_7z_file
|
from launcher.file.extract import extract_7z_file
|
||||||
from launcher.file.utils import ensure_directory_exists, check_command_path
|
from launcher.file.utils import ensure_directory_exists, check_command_path
|
||||||
|
from launcher.instances import manager
|
||||||
from launcher.log import logger
|
from launcher.log import logger
|
||||||
from launcher.sys_config import sys_config
|
from launcher.sys_config import sys_config
|
||||||
|
from launcher.utils import build_base_url
|
||||||
from launcher.webview.events import custom_event, LogType
|
from launcher.webview.events import custom_event, LogType
|
||||||
|
|
||||||
command_list = {
|
command_list = {
|
||||||
"download_git": lambda: init_download("git", download_git_url, os.getcwd()),
|
"download_git": lambda: init_download(
|
||||||
"download_python": lambda: init_download("python", download_python_url, os.getcwd()),
|
"git", build_base_url(download_git_url), os.getcwd()
|
||||||
|
),
|
||||||
|
"download_python": lambda: init_download(
|
||||||
|
"python", build_base_url(download_python_url), os.getcwd()
|
||||||
|
),
|
||||||
"lfs": "git\\bin\\git lfs install",
|
"lfs": "git\\bin\\git lfs install",
|
||||||
"ensurepip": "python\\python -m ensurepip --default-pip",
|
"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",
|
"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 origin {config.conf.branch} --progress",
|
"fetch": lambda: f"..\\git\\bin\\git fetch origin {config.conf.branch} --progress",
|
||||||
"switch": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=100 switch -f {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}",
|
"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_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",
|
"pip_sync": lambda: f"..\\python\\Scripts\\pip-sync -i {mirror_list[config.conf.mirror]} requirements.txt",
|
||||||
"webview": "start ..\\python\\pythonw webview_ui.py",
|
"webview": lambda instance_path="": f'..\\python\\pythonw -X utf8 webview_ui.py "{instance_path}"',
|
||||||
"manager": "start ..\\python\\pythonw manager.py",
|
"cli": lambda path,
|
||||||
|
command: f'..\\python\\pythonw -X utf8 cli.py -p "{path}" {command}',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,34 +68,24 @@ def parse_stderr(stderr_output):
|
||||||
return "未定义的错误"
|
return "未定义的错误"
|
||||||
|
|
||||||
|
|
||||||
def read_stream(stream, log_type, output_list=None):
|
def check_command_end(command_key, output):
|
||||||
def process_lines(text_io):
|
end_keywords = {"webview": {"WebSocket客户端建立连接": "mower_ng已成功运行"}}
|
||||||
for line in iter(text_io.readline, ''):
|
if command_key in end_keywords:
|
||||||
text = line.rstrip('\n').strip()
|
keywords = end_keywords[command_key]
|
||||||
custom_event(log_type, text)
|
for keyword in keywords:
|
||||||
if output_list is not None:
|
if keyword in output:
|
||||||
output_list.append(text)
|
custom_event(LogType.info, keywords[keyword])
|
||||||
|
return True
|
||||||
detected_encoding = 'utf-8'
|
return False
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
class Api:
|
class Api:
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
logger.info("读取配置文件")
|
logger.debug("读取配置文件")
|
||||||
return config.conf.model_dump()
|
return config.conf.model_dump()
|
||||||
|
|
||||||
def save_config(self, conf):
|
def save_config(self, conf):
|
||||||
logger.info(f"更新配置文件{conf}")
|
logger.debug(f"更新配置文件{conf}")
|
||||||
config.conf = config.Conf(**conf)
|
config.conf = config.Conf(**conf)
|
||||||
config.save_conf()
|
config.save_conf()
|
||||||
|
|
||||||
|
@ -85,14 +94,13 @@ class Api:
|
||||||
|
|
||||||
def get_new_version(self):
|
def get_new_version(self):
|
||||||
logger.info("获取最新版本号")
|
logger.info("获取最新版本号")
|
||||||
response = requests.get(get_new_version_url)
|
response = requests.get(build_base_url(get_new_version_url))
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
# 更新启动器本身
|
# 更新启动器本身
|
||||||
def update_self(self, download_url):
|
def update_self(self, download_url):
|
||||||
|
download_url = build_base_url(download_url)
|
||||||
logger.info(f"开始更新启动器 {download_url}")
|
logger.info(f"开始更新启动器 {download_url}")
|
||||||
file_name = os.path.basename(download_url)
|
|
||||||
file_name = "launcher.7z"
|
|
||||||
current_path = os.getcwd()
|
current_path = os.getcwd()
|
||||||
download_tmp_folder = os.path.join(current_path, "download_tmp")
|
download_tmp_folder = os.path.join(current_path, "download_tmp")
|
||||||
# 确保 download_tmp 文件夹存在
|
# 确保 download_tmp 文件夹存在
|
||||||
|
@ -144,10 +152,13 @@ class Api:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return repr(e)
|
return repr(e)
|
||||||
|
|
||||||
def run(self, command, cwd=None):
|
def run(self, command_key, cwd=None, params={}):
|
||||||
command = command_list[command]
|
command = command_list[command_key]
|
||||||
if callable(command):
|
if callable(command):
|
||||||
command = command()
|
try:
|
||||||
|
command = command(**params)
|
||||||
|
except TypeError:
|
||||||
|
command = command()
|
||||||
if callable(command):
|
if callable(command):
|
||||||
return "success" if command() else "failed"
|
return "success" if command() else "failed"
|
||||||
if cwd is not None:
|
if cwd is not None:
|
||||||
|
@ -156,23 +167,46 @@ class Api:
|
||||||
# 执行命令前先判断命令路径是否存在
|
# 执行命令前先判断命令路径是否存在
|
||||||
exist, command_path = check_command_path(command, cwd)
|
exist, command_path = check_command_path(command, cwd)
|
||||||
if not exist:
|
if not exist:
|
||||||
custom_event(LogType.error, f"命令路径不存在:{command_path} 请尝试依赖修复并重新初始化。")
|
custom_event(
|
||||||
|
LogType.error,
|
||||||
|
f"命令路径不存在:{command_path} 请尝试依赖修复并重新初始化。",
|
||||||
|
)
|
||||||
return "failed"
|
return "failed"
|
||||||
try:
|
try:
|
||||||
stdout_stderr = []
|
stdout_stderr = []
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cwd, bufsize=0,
|
command,
|
||||||
universal_newlines=False
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
shell=True,
|
||||||
|
cwd=cwd,
|
||||||
|
bufsize=0,
|
||||||
|
universal_newlines=False,
|
||||||
) as p:
|
) 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))
|
|
||||||
|
|
||||||
stdout_thread.start()
|
def process_lines(text_io):
|
||||||
stderr_thread.start()
|
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.join()
|
detected_encoding = "utf-8"
|
||||||
stderr_thread.join()
|
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:
|
if p.returncode == 0:
|
||||||
return "success"
|
return "success"
|
||||||
|
@ -184,3 +218,90 @@ class Api:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
custom_event(LogType.error, str(e))
|
custom_event(LogType.error, str(e))
|
||||||
return "failed"
|
return "failed"
|
||||||
|
|
||||||
|
def add_instance(self):
|
||||||
|
return manager.add_instance()
|
||||||
|
|
||||||
|
def delete_instance(self, path):
|
||||||
|
instances_dir = os.path.join(os.getcwd(), instances_folder_name)
|
||||||
|
abs_path = os.path.abspath(path)
|
||||||
|
if os.path.commonpath(
|
||||||
|
[abs_path, instances_dir]
|
||||||
|
) == instances_dir and os.path.exists(abs_path):
|
||||||
|
shutil.rmtree(abs_path)
|
||||||
|
|
||||||
|
def migrate_default_instance(self):
|
||||||
|
"""迁移默认实例文件到新实例"""
|
||||||
|
source_path = os.path.join(os.getcwd(), "mower-ng")
|
||||||
|
return manager.migrate_instance(source_path)
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
def cli_control(self, command: str, path: str):
|
||||||
|
"""
|
||||||
|
统一的CLI控制接口,用于执行指定命令并可选地指定工作目录。
|
||||||
|
|
||||||
|
:param command_str: 要执行的命令字符串或命令键(如 "status", "launch" 等)
|
||||||
|
:param path: 实例路径
|
||||||
|
"""
|
||||||
|
if command not in cli_command:
|
||||||
|
custom_event(
|
||||||
|
LogType.error,
|
||||||
|
f"无效的命令字符串或命令键:{command},请检查输入。",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
ret = self.run("cli", "mower-ng", {"command": command, "path": path})
|
||||||
|
if command == "launch" and ret == "success":
|
||||||
|
self.run("cli", "mower-ng", {"command": "webui", "path": path})
|
||||||
|
except Exception as e:
|
||||||
|
custom_event(LogType.error, f"{cli_command[command]} 失败 {repr(e)}")
|
||||||
|
|
||||||
|
def batch_cli_control(self, command):
|
||||||
|
checked_instances = [
|
||||||
|
instance for instance in config.conf.instances if instance.checked
|
||||||
|
]
|
||||||
|
if not checked_instances:
|
||||||
|
custom_event(LogType.warning, "没有选中的实例")
|
||||||
|
return [{"status": False, "message": "No checked instances"}]
|
||||||
|
|
||||||
|
for instance in checked_instances:
|
||||||
|
try:
|
||||||
|
custom_event(LogType.info, f"{instance.name} {cli_command[command]}")
|
||||||
|
self.cli_control(command, instance.path)
|
||||||
|
custom_event(
|
||||||
|
LogType.info, f"{instance.name} {cli_command[command]} 完成"
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
custom_event(
|
||||||
|
LogType.error,
|
||||||
|
f"{instance.name} {cli_command[command]} 失败 {repr(e)}",
|
||||||
|
)
|
||||||
|
|
|
@ -34,15 +34,19 @@ async function initialize_config() {
|
||||||
await init_version()
|
await init_version()
|
||||||
}
|
}
|
||||||
|
|
||||||
const log = ref('')
|
const log = ref([])
|
||||||
provide('log', log)
|
provide('log', log)
|
||||||
const log_ele = ref(null)
|
const log_ele = ref(null)
|
||||||
provide('log_ele', log_ele)
|
provide('log_ele', log_ele)
|
||||||
watch(log, () => {
|
watch(
|
||||||
nextTick(() => {
|
log,
|
||||||
log_ele.value?.scrollTo({ position: 'bottom' })
|
() => {
|
||||||
})
|
nextTick(() => {
|
||||||
})
|
log_ele.value?.scrollTo({ position: 'bottom' })
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (window.pywebview && pywebview.api) {
|
if (window.pywebview && pywebview.api) {
|
||||||
|
@ -53,12 +57,15 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
window.addEventListener('log', (e) => {
|
window.addEventListener('log', (e) => {
|
||||||
log.value += e.detail.log
|
log.value.push(e.detail.log)
|
||||||
|
if (log.value.length > 200) {
|
||||||
|
log.value.shift()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function set_page(value) {
|
function set_page(value) {
|
||||||
log.value = ''
|
log.value.splice(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const running = ref(false)
|
const running = ref(false)
|
||||||
|
@ -89,6 +96,7 @@ provide('new_version', new_version)
|
||||||
class="container"
|
class="container"
|
||||||
v-model:value="conf.page"
|
v-model:value="conf.page"
|
||||||
@update:value="set_page"
|
@update:value="set_page"
|
||||||
|
justify-content="center"
|
||||||
>
|
>
|
||||||
<n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane>
|
<n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane>
|
||||||
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
|
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
|
||||||
|
@ -96,15 +104,17 @@ provide('new_version', new_version)
|
||||||
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
|
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
|
||||||
<n-tab-pane :disabled="running" name="settings">
|
<n-tab-pane :disabled="running" name="settings">
|
||||||
<template #tab>
|
<template #tab>
|
||||||
<n-space :wrap="false">
|
<div class="tab-content">
|
||||||
设置
|
<span>设置</span>
|
||||||
<n-tag v-if="update_able" round type="success">新</n-tag>
|
<n-tag v-if="update_able" class="tag" round type="success">新</n-tag>
|
||||||
</n-space>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<settings />
|
<settings />
|
||||||
</n-tab-pane>
|
</n-tab-pane>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
|
<div class="suffix-container">
|
||||||
|
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</n-tabs>
|
</n-tabs>
|
||||||
</n-notification-provider>
|
</n-notification-provider>
|
||||||
|
@ -117,4 +127,17 @@ provide('new_version', new_version)
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
.suffix-container {
|
||||||
|
margin: 0 4px 6px 4px;
|
||||||
|
}
|
||||||
|
.tab-content {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.tag {
|
||||||
|
margin-left: 4px;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 100%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
30
ui/src/components/BaseMirrorOption.vue
Normal file
30
ui/src/components/BaseMirrorOption.vue
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<script setup>
|
||||||
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
|
|
||||||
|
const conf = useConfigStore().config
|
||||||
|
|
||||||
|
const running = inject('running')
|
||||||
|
|
||||||
|
async function test_connect() {
|
||||||
|
running.value = true
|
||||||
|
await pywebview.api.test_base_url_connect()
|
||||||
|
running.value = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<n-form-item label="镜像模式" :label-style="form_item_label_style">
|
||||||
|
<n-radio-group v-model:value="conf.base_mirror" :disabled="running">
|
||||||
|
<n-flex>
|
||||||
|
<n-radio value="0">默认模式</n-radio>
|
||||||
|
<n-radio value="1">镜像模式(-cf后缀)</n-radio>
|
||||||
|
</n-flex>
|
||||||
|
</n-radio-group>
|
||||||
|
<n-button strong secondary type="primary" size="small" @click="test_connect" :disabled="running"
|
||||||
|
>测试连接</n-button
|
||||||
|
>
|
||||||
|
</n-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
|
@ -11,7 +11,7 @@ const current_state = inject('current_state')
|
||||||
const notification = useNotification()
|
const notification = useNotification()
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
log.value = ''
|
log.value = []
|
||||||
running.value = true
|
running.value = true
|
||||||
for (const [i, step] of steps.value.entries()) {
|
for (const [i, step] of steps.value.entries()) {
|
||||||
current_step.value = i + 1
|
current_step.value = i + 1
|
||||||
|
|
|
@ -5,27 +5,44 @@ import hljs from 'highlight.js/lib/core'
|
||||||
const log = inject('log')
|
const log = inject('log')
|
||||||
const log_ele = inject('log_ele')
|
const log_ele = inject('log_ele')
|
||||||
|
|
||||||
|
const chinesePattern = {
|
||||||
|
className: 'chinese',
|
||||||
|
begin: /[\u4e00-\u9fa5]+/
|
||||||
|
}
|
||||||
|
|
||||||
hljs.registerLanguage('naive-log', () => ({
|
hljs.registerLanguage('naive-log', () => ({
|
||||||
contains: [
|
contains: [
|
||||||
{
|
{
|
||||||
className: 'info',
|
className: 'info',
|
||||||
begin: /\[信息\]/,
|
begin: /^\[信息\]/,
|
||||||
end: /$/
|
end: /$/,
|
||||||
|
returnBegin: true,
|
||||||
|
returnEnd: true,
|
||||||
|
contains: [chinesePattern]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
className: 'error',
|
className: 'error',
|
||||||
begin: /\[错误\]/,
|
begin: /^\[错误\]/,
|
||||||
end: /$/
|
end: /$/,
|
||||||
|
returnBegin: true,
|
||||||
|
returnEnd: true,
|
||||||
|
contains: [chinesePattern]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
className: 'execute_command',
|
className: 'execute_command',
|
||||||
begin: /\[执行命令\]/,
|
begin: /^\[执行命令\]/,
|
||||||
end: /$/
|
end: /$/,
|
||||||
|
returnBegin: true,
|
||||||
|
returnEnd: true,
|
||||||
|
contains: [chinesePattern]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
className: 'command_out',
|
className: 'command_out',
|
||||||
begin: /\[命令输出\]/,
|
begin: /^\[命令输出\]/,
|
||||||
end: /$/
|
end: /$/,
|
||||||
|
returnBegin: true,
|
||||||
|
returnEnd: true,
|
||||||
|
contains: [chinesePattern]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
|
@ -34,7 +51,7 @@ hljs.registerLanguage('naive-log', () => ({
|
||||||
<template>
|
<template>
|
||||||
<n-config-provider :theme="darkTheme" class="provider" :hljs="hljs">
|
<n-config-provider :theme="darkTheme" class="provider" :hljs="hljs">
|
||||||
<n-card class="full" content-style="height: 100%">
|
<n-card class="full" content-style="height: 100%">
|
||||||
<n-log :log="log" class="full selectable-log" ref="log_ele" language="naive-log" />
|
<n-log :lines="log" class="full selectable-log" ref="log_ele" language="naive-log" />
|
||||||
</n-card>
|
</n-card>
|
||||||
</n-config-provider>
|
</n-config-provider>
|
||||||
</template>
|
</template>
|
||||||
|
@ -54,22 +71,3 @@ hljs.registerLanguage('naive-log', () => ({
|
||||||
user-select: text;
|
user-select: text;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
|
||||||
pre {
|
|
||||||
word-break: break-all !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.n-code pre .hljs-info {
|
|
||||||
color: #33ff33;
|
|
||||||
}
|
|
||||||
.n-code pre .hljs-error {
|
|
||||||
color: #ff0000;
|
|
||||||
}
|
|
||||||
.n-code pre .hljs-execute_command {
|
|
||||||
color: #edaf1f;
|
|
||||||
}
|
|
||||||
.n-code pre .hljs-command_out {
|
|
||||||
color: #ffffff;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import 'vfonts/Lato.css'
|
|
||||||
import 'vfonts/FiraCode.css'
|
import 'vfonts/FiraCode.css'
|
||||||
|
import './styles/global.css'
|
||||||
|
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const steps = ref([
|
const steps = ref([
|
||||||
{
|
{
|
||||||
title: '下载 git、python',
|
title: '下载 git、python',
|
||||||
|
@ -22,6 +24,9 @@ provide('current_state', current_state)
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
|
<base-mirror-option />
|
||||||
|
</n-form>
|
||||||
<n-alert title="以下步骤仅需运行一次" type="warning" />
|
<n-alert title="以下步骤仅需运行一次" type="warning" />
|
||||||
<n-steps :current="current_step" :status="current_state" size="small">
|
<n-steps :current="current_step" :status="current_state" size="small">
|
||||||
<n-step v-for="step in steps" :title="step.title" />
|
<n-step v-for="step in steps" :title="step.title" />
|
||||||
|
|
|
@ -1,37 +1,285 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
function webview() {
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
pywebview.api.run('webview', 'mower-ng')
|
import { NButton } from 'naive-ui'
|
||||||
|
import {
|
||||||
|
Add,
|
||||||
|
Pencil,
|
||||||
|
Play,
|
||||||
|
Folder,
|
||||||
|
TrashOutline,
|
||||||
|
Archive,
|
||||||
|
Browsers,
|
||||||
|
Stop,
|
||||||
|
Search
|
||||||
|
} from '@vicons/ionicons5'
|
||||||
|
|
||||||
|
const notification = useNotification()
|
||||||
|
|
||||||
|
const config_store = useConfigStore()
|
||||||
|
const conf = config_store.config
|
||||||
|
const instance_name_input_refs = ref([])
|
||||||
|
const update_instance_name_index = ref(null)
|
||||||
|
const migrate_options = [
|
||||||
|
{
|
||||||
|
label: '迁移单开配置',
|
||||||
|
key: 'default'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '迁移多开配置',
|
||||||
|
key: 'instances'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const check_all = computed(
|
||||||
|
() => conf.instances.length > 0 && conf.instances.every((item) => item.checked)
|
||||||
|
)
|
||||||
|
const check_part = computed(() => !check_all.value && conf.instances.some((item) => item.checked))
|
||||||
|
function click_check_all(ckecked) {
|
||||||
|
if (ckecked) {
|
||||||
|
conf.instances.forEach((item) => {
|
||||||
|
item.checked = true
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
conf.instances.forEach((item) => {
|
||||||
|
item.checked = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function setInstanceNameInputRef(el, index) {
|
||||||
|
if (el) {
|
||||||
|
instance_name_input_refs.value[index] = el
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function add_instance() {
|
||||||
|
const instance_path = await pywebview.api.add_instance()
|
||||||
|
conf.instances.push({
|
||||||
|
checked: false,
|
||||||
|
name: '新实例',
|
||||||
|
path: instance_path
|
||||||
|
})
|
||||||
|
}
|
||||||
|
async function delete_instance(index, path) {
|
||||||
|
await pywebview.api.delete_instance(path)
|
||||||
|
conf.instances.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
function manager() {
|
function start_update_instance_name(index) {
|
||||||
pywebview.api.run('manager', 'mower-ng')
|
update_instance_name_index.value = index
|
||||||
|
nextTick(() => {
|
||||||
|
instance_name_input_refs.value[index]?.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function end_update_instance_name() {
|
||||||
|
update_instance_name_index.value = null
|
||||||
|
}
|
||||||
|
function open_folder(path) {
|
||||||
|
pywebview.api.open_folder(path)
|
||||||
|
}
|
||||||
|
function cli(command, instance) {
|
||||||
|
pywebview.api.cli_control(command, instance.path)
|
||||||
|
}
|
||||||
|
function batch_cli_control(command) {
|
||||||
|
pywebview.api.batch_cli_control(command)
|
||||||
|
}
|
||||||
|
async function handle_migrate(key) {
|
||||||
|
if (key == 'default') {
|
||||||
|
const response = await pywebview.api.migrate_default_instance()
|
||||||
|
console.log(response)
|
||||||
|
if (response.status) {
|
||||||
|
conf.instances.push({
|
||||||
|
checked: false,
|
||||||
|
name: '默认实例',
|
||||||
|
path: response.data
|
||||||
|
})
|
||||||
|
notification['success']({
|
||||||
|
content: '信息',
|
||||||
|
meta: response.message,
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
notification['error']({
|
||||||
|
content: '错误',
|
||||||
|
meta: response.message,
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const response = await pywebview.api.migrate_instances_config()
|
||||||
|
console.log('多开配置内容:', response)
|
||||||
|
if (response.data) {
|
||||||
|
await config_store.load_config()
|
||||||
|
conf.instances = [...config_store.config.instances]
|
||||||
|
}
|
||||||
|
if (response.status) {
|
||||||
|
notification['info']({
|
||||||
|
title: '信息',
|
||||||
|
content: response.message,
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
notification['error']({
|
||||||
|
title: '错误',
|
||||||
|
content: response.message,
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-flex
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
vertical
|
<n-space class="top" justify="space-between">
|
||||||
style="
|
<n-space>
|
||||||
gap: 16px;
|
<n-button class="launch-btn" type="primary" secondary @click="add_instance">
|
||||||
height: 100%;
|
<template #icon>
|
||||||
padding: 16px;
|
<n-icon :component="Add"></n-icon>
|
||||||
box-sizing: border-box;
|
</template>
|
||||||
justify-content: center;
|
添加实例
|
||||||
align-items: center;
|
</n-button>
|
||||||
"
|
<n-button
|
||||||
>
|
class="launch-btn"
|
||||||
<n-button class="launch-btn" type="primary" secondary size="large" @click="webview">
|
type="primary"
|
||||||
单开运行
|
secondary
|
||||||
</n-button>
|
@click="batch_cli_control('launch')"
|
||||||
<n-button class="launch-btn" type="primary" secondary size="large" @click="manager">
|
:disabled="!check_all && !check_part"
|
||||||
多开器
|
>
|
||||||
</n-button>
|
<template #icon>
|
||||||
|
<n-icon :component="Play"></n-icon>
|
||||||
|
</template>
|
||||||
|
启动所选实例
|
||||||
|
</n-button>
|
||||||
|
<n-button
|
||||||
|
class="launch-btn"
|
||||||
|
type="error"
|
||||||
|
secondary
|
||||||
|
@click="batch_cli_control('exit')"
|
||||||
|
:disabled="!check_all && !check_part"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Stop"></n-icon>
|
||||||
|
</template>
|
||||||
|
停止所选实例
|
||||||
|
</n-button>
|
||||||
|
<n-dropdown trigger="click" :options="migrate_options" @select="handle_migrate">
|
||||||
|
<n-button class="launch-btn" type="primary" secondary>
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Archive"></n-icon>
|
||||||
|
</template>
|
||||||
|
迁移配置
|
||||||
|
</n-button>
|
||||||
|
</n-dropdown>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<div class="is_show_log_switch">
|
||||||
|
<n-switch v-model:value="conf.is_show_log" />
|
||||||
|
显示日志
|
||||||
|
</div>
|
||||||
|
</n-space>
|
||||||
|
<n-list class="instance_list" bordered>
|
||||||
|
<n-list-item class="instance_list_item">
|
||||||
|
<template #prefix>
|
||||||
|
<n-checkbox
|
||||||
|
v-model:checked="check_all"
|
||||||
|
:indeterminate="check_part"
|
||||||
|
style="white-space: nowrap"
|
||||||
|
@update:checked="click_check_all"
|
||||||
|
>全选</n-checkbox
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
</n-list-item>
|
||||||
|
<n-list-item class="instance_list_item" v-for="(item, index) in conf.instances" :key="index">
|
||||||
|
<template #prefix>
|
||||||
|
<n-checkbox v-model:checked="item.checked"></n-checkbox>
|
||||||
|
</template>
|
||||||
|
<n-space vertical>
|
||||||
|
<n-space v-if="update_instance_name_index != index">
|
||||||
|
<n-text class="instance_name">{{ item.name }}</n-text>
|
||||||
|
<n-button size="tiny" @click="start_update_instance_name(index)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Pencil"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
</n-space>
|
||||||
|
<n-input
|
||||||
|
v-else
|
||||||
|
class="instance_name_input"
|
||||||
|
:ref="(el) => setInstanceNameInputRef(el, index)"
|
||||||
|
v-model:value="item.name"
|
||||||
|
@blur="end_update_instance_name"
|
||||||
|
clearable
|
||||||
|
></n-input>
|
||||||
|
</n-space>
|
||||||
|
<template #suffix>
|
||||||
|
<n-space :wrap="false">
|
||||||
|
<n-button type="primary" ghost size="small" @click="cli('status', item)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Search"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-button type="primary" size="small" @click="cli('launch', item)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Play"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-button type="primary" ghost size="small" @click="cli('webui', item)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Browsers"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-button type="error" ghost size="small" @click="cli('exit', item)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Stop"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-button type="primary" ghost size="small" @click="open_folder(item.path)">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="Folder"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-popconfirm @positive-click="delete_instance(index, item.path)">
|
||||||
|
<template #trigger>
|
||||||
|
<n-button type="error" ghost size="small">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="TrashOutline"></n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
</template>
|
||||||
|
删除操作将导致实例配置丢失,请谨慎操作。
|
||||||
|
</n-popconfirm>
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
</n-list-item>
|
||||||
|
</n-list>
|
||||||
|
<log-component v-show="conf.is_show_log" class="log" />
|
||||||
</n-flex>
|
</n-flex>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.launch-btn {
|
.launch-btn {
|
||||||
width: 120px;
|
height: 38px;
|
||||||
height: 48px;
|
}
|
||||||
|
.instance_list {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.instance_list_item {
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
.instance_name {
|
||||||
|
margin-left: 12px;
|
||||||
|
}
|
||||||
|
.instance_name_input {
|
||||||
|
height: 35px;
|
||||||
|
}
|
||||||
|
.log {
|
||||||
|
min-height: 40vh;
|
||||||
|
max-height: 40vh;
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
.top {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.is_show_log_switch {
|
||||||
|
margin-right: 20px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { SyncCircle } from '@vicons/ionicons5'
|
import { Sync } from '@vicons/ionicons5'
|
||||||
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const notification = useNotification()
|
const notification = useNotification()
|
||||||
|
|
||||||
|
@ -57,17 +59,20 @@ async function check_update() {
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
<n-form-item label="版本">
|
<base-mirror-option />
|
||||||
|
<n-form-item label="版本" :label-style="form_item_label_style">
|
||||||
<n-space align="center">
|
<n-space align="center">
|
||||||
{{ version }}
|
{{ version }}
|
||||||
<n-button
|
<n-button
|
||||||
type="success"
|
type="success"
|
||||||
|
secondary
|
||||||
|
size="small"
|
||||||
:loading="check_running"
|
:loading="check_running"
|
||||||
:disabled="running"
|
:disabled="running"
|
||||||
@click="check_update"
|
@click="check_update"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon :component="SyncCircle"></n-icon>
|
<n-icon :component="Sync"></n-icon>
|
||||||
</template>
|
</template>
|
||||||
检查更新
|
检查更新
|
||||||
</n-button>
|
</n-button>
|
||||||
|
@ -76,11 +81,14 @@ async function check_update() {
|
||||||
<n-alert style="margin: 8px 0" type="success" v-if="update_able">
|
<n-alert style="margin: 8px 0" type="success" v-if="update_able">
|
||||||
<template #header>
|
<template #header>
|
||||||
最新版本:{{ `${new_version.tag_name} ${new_version.name}` }}
|
最新版本:{{ `${new_version.tag_name} ${new_version.name}` }}
|
||||||
<n-button style="float: right" @click="open_new_version_html">了解此版本</n-button>
|
<n-button type="success" secondary style="float: right" @click="open_new_version_html">
|
||||||
|
了解此版本
|
||||||
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
<n-space>
|
<n-space>
|
||||||
<n-button
|
<n-button
|
||||||
type="success"
|
type="success"
|
||||||
|
secondary
|
||||||
:loading="update_self_running"
|
:loading="update_self_running"
|
||||||
:disabled="running"
|
:disabled="running"
|
||||||
@click="update_self"
|
@click="update_self"
|
||||||
|
@ -90,5 +98,6 @@ async function check_update() {
|
||||||
</n-space>
|
</n-space>
|
||||||
</n-alert>
|
</n-alert>
|
||||||
</n-form>
|
</n-form>
|
||||||
|
<log-component />
|
||||||
</n-flex>
|
</n-flex>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useConfigStore } from '@/stores/config.js'
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const conf = useConfigStore().config
|
const conf = useConfigStore().config
|
||||||
const branch = ref(null)
|
const branch = ref(null)
|
||||||
const mirror = ref(null)
|
const mirror = ref(null)
|
||||||
|
const running = inject('running')
|
||||||
|
|
||||||
const steps = computed(() => [
|
const steps = computed(() => [
|
||||||
{
|
{
|
||||||
title: '更新源码',
|
title: '更新源码',
|
||||||
command: ['fetch', 'switch', 'reset'],
|
command: ['set_remote', 'set_lfs', 'fetch', 'switch', 'reset'],
|
||||||
cwd: 'mower-ng'
|
cwd: 'mower-ng'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -27,16 +30,17 @@ provide('current_state', current_state)
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
<n-form-item label="mower-ng 代码分支">
|
<base-mirror-option />
|
||||||
<n-radio-group v-model:value="conf.branch">
|
<n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style">
|
||||||
|
<n-radio-group v-model:value="conf.branch" :disabled="running">
|
||||||
<n-flex>
|
<n-flex>
|
||||||
<n-radio value="fast">测试版</n-radio>
|
<n-radio value="fast">测试版</n-radio>
|
||||||
<n-radio value="slow">稳定版</n-radio>
|
<n-radio value="slow">稳定版</n-radio>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
</n-radio-group>
|
</n-radio-group>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="PyPI 仓库镜像">
|
<n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style">
|
||||||
<n-radio-group v-model:value="conf.mirror">
|
<n-radio-group v-model:value="conf.mirror" :disabled="running">
|
||||||
<n-flex>
|
<n-flex>
|
||||||
<n-radio value="pypi">PyPI</n-radio>
|
<n-radio value="pypi">PyPI</n-radio>
|
||||||
<n-radio value="aliyun">阿里云镜像站</n-radio>
|
<n-radio value="aliyun">阿里云镜像站</n-radio>
|
||||||
|
|
|
@ -1,27 +1,43 @@
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
export const useConfigStore = defineStore('config', () => {
|
export const useConfigStore = defineStore('config', () => {
|
||||||
class Config {
|
class Instance {
|
||||||
constructor(conf) {
|
constructor(instance) {
|
||||||
this.page = conf.page
|
this.checked = instance.checked
|
||||||
this.branch = conf.branch
|
this.name = instance.name
|
||||||
this.mirror = conf.mirror
|
this.path = instance.path
|
||||||
this.is_already_show_doc = conf.is_already_show_doc
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = ref({})
|
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
|
||||||
|
// 启动程序 LaunchPart
|
||||||
|
this.instances = []
|
||||||
|
this.is_show_log = conf.is_show_log
|
||||||
|
// 其他部分 OtherPart
|
||||||
|
this.base_mirror = conf.base_mirror
|
||||||
|
Object.assign(this, conf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = reactive({})
|
||||||
|
|
||||||
async function load_config() {
|
async function load_config() {
|
||||||
const conf = await pywebview.api.load_config()
|
const conf = await pywebview.api.load_config()
|
||||||
config.value = new Config(conf)
|
Object.assign(config, new Config(conf))
|
||||||
console.log('config.value', config.value)
|
console.log('响应式配置已更新', config)
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
config,
|
config,
|
||||||
() => {
|
() => {
|
||||||
pywebview.api.save_config(config.value)
|
pywebview.api.save_config(config)
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
)
|
)
|
||||||
|
|
43
ui/src/styles/global.css
Normal file
43
ui/src/styles/global.css
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* src/assets/styles/global.css */
|
||||||
|
|
||||||
|
/* 日志样式 */
|
||||||
|
.n-code pre {
|
||||||
|
word-break: break-all !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-info {
|
||||||
|
color: #33ff33;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-error {
|
||||||
|
color: #ff0000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-execute_command {
|
||||||
|
color: #edaf1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-command_out {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-chinese {
|
||||||
|
font-family: '微软雅黑', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保 chinese 类在所有父级类下生效 */
|
||||||
|
.n-code pre .hljs-info .hljs-chinese {
|
||||||
|
color: #33ff33;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-error .hljs-chinese {
|
||||||
|
color: #ff0000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-execute_command .hljs-chinese {
|
||||||
|
color: #edaf1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.n-code pre .hljs-command_out .hljs-chinese {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
3
ui/src/styles/styles.js
Normal file
3
ui/src/styles/styles.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const form_item_label_style = {
|
||||||
|
alignSelf: 'center'
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue