Compare commits

..

13 commits
v0.6 ... main

16 changed files with 383 additions and 162 deletions

View file

@ -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 import BaseModel, model_validator
from pydantic_core import PydanticUndefined from pydantic_core import PydanticUndefined
@ -15,6 +15,18 @@ class ConfModel(BaseModel):
data[name] = expected_type 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
@ -55,9 +67,17 @@ class LaunchPart(ConfModel):
is_show_log: bool = False 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, LaunchPart,
OtherPart,
): ):
pass pass

View file

@ -8,25 +8,41 @@ 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 = ( get_new_version_url = (
"https://git-cf.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest" "https://git-cf.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_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-cf.zhaozuohong.vip/mower-ng/mower-ng.git"
# pip镜像地址 # pip镜像地址
mirror_list = { mirror_list = {
"pypi": "https://pypi.org/simple", "pypi": "https://pypi.org/simple",
"aliyun": "https://mirrors.aliyun.com/pypi/simple/", "aliyun": "https://mirrors.aliyun.com/pypi/simple/",
"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",
"ustc": "https://mirrors.ustc.edu.cn/pypi/simple",
} }
# 实例文件夹名 # 实例文件夹名
instances_folder_name = "instances" instances_folder_name = "instances"
# cli命令
cli_command = {
"status": "获取mower-ng实例状态",
"launch": "启动mower-ng进程",
"exit": "停止mower-ng进程",
"kill": "强制退出mower-ng进程",
"start": "开始运行调度器",
"stop": "停止运行调度器",
"webui": "在浏览器中打开网页面板",
"log": "通过WebSocket获取日志",
}

View file

@ -1,5 +1,5 @@
{ {
"version": "v0.6", "version": "v0.7.1",
"url": "ui/dist/index.html", "url": "ui/dist/index.html",
"log_level": "INFO", "log_level": "INFO",
"debug": false "debug": false

12
launcher/utils.py Normal file
View 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

View file

@ -2,7 +2,7 @@ import io
import os import os
import shutil 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
@ -11,7 +11,6 @@ from subprocess import Popen
import requests import requests
from launcher import config from launcher import config
from launcher.config.conf import LaunchPart
from launcher.constants import ( from launcher.constants import (
download_git_url, download_git_url,
download_python_url, download_python_url,
@ -20,6 +19,8 @@ from launcher.constants import (
mirror_list, mirror_list,
file_name, file_name,
instances_folder_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
@ -27,23 +28,29 @@ from launcher.file.utils import ensure_directory_exists, check_command_path
from launcher.instances import manager 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(
"git", build_base_url(download_git_url), os.getcwd()
),
"download_python": lambda: init_download( "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", "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-cf.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": 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}", "cli": lambda path,
command: f'..\\python\\pythonw -X utf8 cli.py -p "{path}" {command}',
} }
@ -87,11 +94,12 @@ 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}")
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")
@ -222,28 +230,6 @@ class Api:
) == instances_dir and os.path.exists(abs_path): ) == instances_dir and os.path.exists(abs_path):
shutil.rmtree(abs_path) shutil.rmtree(abs_path)
def start_checked_instance(self):
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"}]
def _run_instance(instance: LaunchPart.Instance):
self.run(
"webview",
"mower-ng",
{"instance_path": instance.path},
)
# 创建并启动线程 目前进程依然有阻塞,待优化
for instance in checked_instances:
thread = threading.Thread(
target=_run_instance, args=(instance,), daemon=True
)
thread.start()
def migrate_default_instance(self): def migrate_default_instance(self):
"""迁移默认实例文件到新实例""" """迁移默认实例文件到新实例"""
source_path = os.path.join(os.getcwd(), "mower-ng") source_path = os.path.join(os.getcwd(), "mower-ng")
@ -252,3 +238,70 @@ class Api:
def migrate_instances_config(self): def migrate_instances_config(self):
"""迁移多开配置""" """迁移多开配置"""
return manager.migrate_instances_config() 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)}",
)

View file

@ -89,35 +89,34 @@ provide('new_version', new_version)
<n-spin v-if="loading" class="container"> <n-spin v-if="loading" class="container">
<template #description>加载中</template> <template #description>加载中</template>
</n-spin> </n-spin>
<n-notification-provider v-else> <n-tabs
<n-tabs type="card"
type="card" placement="left"
placement="left" 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"
justify-content="center" v-else
> >
<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>
<n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane> <n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane>
<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>
<div class="tab-content"> <div class="tab-content">
<span>设置</span> <span>设置</span>
<n-tag v-if="update_able" class="tag" round type="success"></n-tag> <n-tag v-if="update_able" class="tag" round type="success"></n-tag>
</div>
</template>
<settings />
</n-tab-pane>
<template #suffix>
<div class="suffix-container">
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
</div> </div>
</template> </template>
</n-tabs> <settings />
</n-notification-provider> </n-tab-pane>
<template #suffix>
<div class="suffix-container">
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
</div>
</template>
</n-tabs>
<n-global-style /> <n-global-style />
</n-config-provider> </n-config-provider>
</template> </template>

View 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>

View file

@ -1,6 +1,7 @@
<script setup> <script setup>
import PlayIcon from '@vicons/ionicons5/Play' import PlayIcon from '@vicons/ionicons5/Play'
import { inject } from 'vue' import { inject } from 'vue'
import { notify } from '@/utils/naiveDiscrete.js'
const running = inject('running') const running = inject('running')
const log = inject('log') const log = inject('log')
@ -8,8 +9,6 @@ const steps = inject('steps')
const current_step = inject('current_step') const current_step = inject('current_step')
const current_state = inject('current_state') const current_state = inject('current_state')
const notification = useNotification()
async function start() { async function start() {
log.value = [] log.value = []
running.value = true running.value = true
@ -20,22 +19,14 @@ async function start() {
if ((await pywebview.api.run(cmd, step.cwd)) == 'failed') { if ((await pywebview.api.run(cmd, step.cwd)) == 'failed') {
current_state.value = 'error' current_state.value = 'error'
running.value = false running.value = false
notification['error']({ notify.error('命令运行失败')
content: '错误',
meta: '命令运行失败',
duration: 3000
})
return return
} }
} }
} }
current_state.value = 'finish' current_state.value = 'finish'
running.value = false running.value = false
notification['info']({ notify.info('命令运行完成')
content: '提示',
meta: '命令运行完成',
duration: 3000
})
} }
</script> </script>

View file

@ -1,4 +1,3 @@
import 'vfonts/Lato.css'
import 'vfonts/FiraCode.css' import 'vfonts/FiraCode.css'
import './styles/global.css' import './styles/global.css'

View file

@ -1,26 +1,15 @@
<script setup> <script setup>
import { notify } from '@/utils/naiveDiscrete.js'
const running = inject('running') const running = inject('running')
const notification = useNotification()
async function rm_site_packages_and_python_scripts() { async function rm_site_packages_and_python_scripts() {
running.value = true running.value = true
notification['info']({ notify.info('开始移除site-packages和python/Script目录')
content: '提示',
meta: '开始移除site-packages和python/Script目录',
duration: 3000
})
const response = await pywebview.api.rm_site_packages() const response = await pywebview.api.rm_site_packages()
notification['info']({ notify.info(response)
content: '提示',
meta: response,
duration: 3000
})
const response2 = await pywebview.api.rm_python_scripts() const response2 = await pywebview.api.rm_python_scripts()
notification['info']({ notify.info(response2)
content: '提示',
meta: response2,
duration: 3000
})
running.value = false running.value = false
} }
</script> </script>

View file

@ -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" />

View file

@ -1,9 +1,18 @@
<script setup> <script setup>
import { useConfigStore } from '@/stores/config.js' import { useConfigStore } from '@/stores/config.js'
import { NButton } from 'naive-ui' import { NButton } from 'naive-ui'
import { Add, Pencil, Play, Folder, TrashOutline, Archive } from '@vicons/ionicons5' import {
Add,
const notification = useNotification() Pencil,
Play,
Folder,
TrashOutline,
Archive,
Browsers,
Stop,
Search
} from '@vicons/ionicons5'
import { notify } from '@/utils/naiveDiscrete.js'
const config_store = useConfigStore() const config_store = useConfigStore()
const conf = config_store.config const conf = config_store.config
@ -62,15 +71,13 @@ function end_update_instance_name() {
update_instance_name_index.value = null update_instance_name_index.value = null
} }
function open_folder(path) { function open_folder(path) {
pywebview.api.run('open_folder', null, { folder_path: path }) pywebview.api.open_folder(path)
} }
function start_instance(instance) { function cli(command, instance) {
pywebview.api.run('webview', 'mower-ng', { pywebview.api.cli_control(command, instance.path)
instance_path: instance.path
})
} }
function start_checked_instance() { function batch_cli_control(command) {
pywebview.api.start_checked_instance() pywebview.api.batch_cli_control(command)
} }
async function handle_migrate(key) { async function handle_migrate(key) {
if (key == 'default') { if (key == 'default') {
@ -82,17 +89,9 @@ async function handle_migrate(key) {
name: '默认实例', name: '默认实例',
path: response.data path: response.data
}) })
notification['success']({ notify.success(response.message)
content: '信息',
meta: response.message,
duration: 3000
})
} else { } else {
notification['error']({ notify.error(response.message)
content: '错误',
meta: response.message,
duration: 3000
})
} }
} else { } else {
const response = await pywebview.api.migrate_instances_config() const response = await pywebview.api.migrate_instances_config()
@ -102,17 +101,9 @@ async function handle_migrate(key) {
conf.instances = [...config_store.config.instances] conf.instances = [...config_store.config.instances]
} }
if (response.status) { if (response.status) {
notification['info']({ notify.info(response.message)
title: '信息',
content: response.message,
duration: 3000
})
} else { } else {
notification['error']({ notify.error(response.message)
title: '错误',
content: response.message,
duration: 3000
})
} }
} }
} }
@ -132,7 +123,7 @@ async function handle_migrate(key) {
class="launch-btn" class="launch-btn"
type="primary" type="primary"
secondary secondary
@click="start_checked_instance" @click="batch_cli_control('launch')"
:disabled="!check_all && !check_part" :disabled="!check_all && !check_part"
> >
<template #icon> <template #icon>
@ -140,6 +131,18 @@ async function handle_migrate(key) {
</template> </template>
启动所选实例 启动所选实例
</n-button> </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-dropdown trigger="click" :options="migrate_options" @select="handle_migrate">
<n-button class="launch-btn" type="primary" secondary> <n-button class="launch-btn" type="primary" secondary>
<template #icon> <template #icon>
@ -155,8 +158,8 @@ async function handle_migrate(key) {
显示日志 显示日志
</div> </div>
</n-space> </n-space>
<n-list class="instance-list" bordered> <n-list class="instance_list" bordered>
<n-list-item> <n-list-item class="instance_list_item">
<template #prefix> <template #prefix>
<n-checkbox <n-checkbox
v-model:checked="check_all" v-model:checked="check_all"
@ -167,38 +170,55 @@ async function handle_migrate(key) {
> >
</template> </template>
</n-list-item> </n-list-item>
<n-list-item v-for="(item, index) in conf.instances" :key="index"> <n-list-item class="instance_list_item" v-for="(item, index) in conf.instances" :key="index">
<template #prefix> <template #prefix>
<n-checkbox v-model:checked="item.checked"></n-checkbox> <n-checkbox v-model:checked="item.checked"></n-checkbox>
</template> </template>
<n-space vertical> <n-space vertical>
<n-space v-if="update_instance_name_index != index"> <n-space v-if="update_instance_name_index != index">
<n-text>{{ item.name }}</n-text> <n-text class="instance_name">{{ item.name }}</n-text>
<n-button size="tiny" @click="start_update_instance_name(index)"> <n-button size="tiny" @click="start_update_instance_name(index)">
<template #icon> <template #icon>
<n-icon :component="Pencil"></n-icon> <n-icon :component="Pencil"></n-icon>
</template> </template>
</n-button> </n-button>
<n-button @click="open_folder(item.path)" size="tiny">
<template #icon>
<n-icon :component="Folder"></n-icon>
</template>
</n-button>
</n-space> </n-space>
<n-input <n-input
v-else v-else
class="instance_name_input"
:ref="(el) => setInstanceNameInputRef(el, index)" :ref="(el) => setInstanceNameInputRef(el, index)"
v-model:value="item.name" v-model:value="item.name"
@blur="end_update_instance_name" @blur="end_update_instance_name"
clearable
></n-input> ></n-input>
</n-space> </n-space>
<template #suffix> <template #suffix>
<n-space :wrap="false"> <n-space :wrap="false">
<n-button type="primary" size="small" @click="start_instance(item)"> <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> <template #icon>
<n-icon :component="Play"></n-icon> <n-icon :component="Play"></n-icon>
</template> </template>
</n-button> </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)"> <n-popconfirm @positive-click="delete_instance(index, item.path)">
<template #trigger> <template #trigger>
<n-button type="error" ghost size="small"> <n-button type="error" ghost size="small">
@ -221,9 +241,18 @@ async function handle_migrate(key) {
.launch-btn { .launch-btn {
height: 38px; height: 38px;
} }
.instance-list { .instance_list {
overflow: auto; overflow: auto;
} }
.instance_list_item {
height: 50px;
}
.instance_name {
margin-left: 12px;
}
.instance_name_input {
height: 35px;
}
.log { .log {
min-height: 40vh; min-height: 40vh;
max-height: 40vh; max-height: 40vh;
@ -234,5 +263,6 @@ async function handle_migrate(key) {
} }
.is_show_log_switch { .is_show_log_switch {
margin-right: 20px; margin-right: 20px;
text-align: center;
} }
</style> </style>

View file

@ -1,8 +1,8 @@
<script setup> <script setup>
import { SyncCircle } from '@vicons/ionicons5' import { Sync } from '@vicons/ionicons5'
import { form_item_label_style } from '@/styles/styles.js' import { form_item_label_style } from '@/styles/styles.js'
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
const notification = useNotification() import { notify } from '@/utils/naiveDiscrete.js'
const update_able = inject('update_able') const update_able = inject('update_able')
const running = inject('running') const running = inject('running')
@ -18,11 +18,7 @@ async function update_self() {
const response = await pywebview.api.update_self( const response = await pywebview.api.update_self(
new_version.value['assets'][0]['browser_download_url'] new_version.value['assets'][0]['browser_download_url']
) )
notification['error']({ notify.error(response)
content: '错误',
meta: response,
duration: 3000
})
update_self_running.value = false update_self_running.value = false
running.value = false running.value = false
} }
@ -37,18 +33,10 @@ async function check_update() {
new_version.value = await pywebview.api.get_new_version() new_version.value = await pywebview.api.get_new_version()
if (new_version.value.tag_name > version.value) { if (new_version.value.tag_name > version.value) {
update_able.value = true update_able.value = true
notification['info']({ notify.info('有新版本可更新')
content: '提示',
meta: '有新版本可更新',
duration: 3000
})
} else { } else {
update_able.value = false update_able.value = false
notification['info']({ notify.info('当前已是最新版本')
content: '提示',
meta: '当前已是最新版本',
duration: 3000
})
} }
check_running.value = false check_running.value = false
running.value = false running.value = false
@ -58,17 +46,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">
<base-mirror-option />
<n-form-item label="版本" :label-style="form_item_label_style"> <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>
@ -77,11 +68,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"

View file

@ -1,15 +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 { 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'
}, },
{ {
@ -18,6 +20,28 @@ const steps = computed(() => [
cwd: 'mower-ng' cwd: 'mower-ng'
} }
]) ])
const mirror_options = [
{
label: 'PyPI',
value: 'pypi'
},
{
label: '阿里云镜像源',
value: 'aliyun'
},
{
label: '上海交通大学镜像源',
value: 'sjtu'
},
{
label: '清华大学镜像源',
value: 'tuna'
},
{
label: '中国科学技术大学镜像源',
value: 'ustc'
}
]
provide('steps', steps) provide('steps', steps)
const current_step = ref(1) const current_step = ref(1)
provide('current_step', current_step) provide('current_step', current_step)
@ -28,8 +52,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"> <n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
<base-mirror-option />
<n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style"> <n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style">
<n-radio-group v-model:value="conf.branch"> <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>
@ -37,14 +62,7 @@ provide('current_state', current_state)
</n-radio-group> </n-radio-group>
</n-form-item> </n-form-item>
<n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style"> <n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style">
<n-radio-group v-model:value="conf.mirror"> <n-select v-model:value="conf.mirror" :options="mirror_options" :disabled="running" />
<n-flex>
<n-radio value="pypi">PyPI</n-radio>
<n-radio value="aliyun">阿里云镜像站</n-radio>
<n-radio value="sjtu">上海交通大学镜像站</n-radio>
<n-radio value="tuna">清华大学镜像站</n-radio>
</n-flex>
</n-radio-group>
</n-form-item> </n-form-item>
</n-form> </n-form>
<n-steps :current="current_step" :status="current_state" size="small"> <n-steps :current="current_step" :status="current_state" size="small">

View file

@ -20,6 +20,8 @@ export const useConfigStore = defineStore('config', () => {
// 启动程序 LaunchPart // 启动程序 LaunchPart
this.instances = [] this.instances = []
this.is_show_log = conf.is_show_log this.is_show_log = conf.is_show_log
// 其他部分 OtherPart
this.base_mirror = conf.base_mirror
Object.assign(this, conf) Object.assign(this, conf)
} }
} }

View file

@ -0,0 +1,63 @@
import { createDiscreteApi, darkTheme, lightTheme } from 'naive-ui'
// 创建全局单例
const { message, dialog, notification, loadingBar } = createDiscreteApi(
['message', 'dialog', 'notification', 'loadingBar'],
{
configProviderProps: {
// 全局主题配置(示例使用系统主题)
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? darkTheme : lightTheme
}
}
)
// 创建统一的工厂函数
const createMessager =
(handler, defaults) =>
(content, options = {}) => {
const mergedOptions =
typeof content === 'string'
? { content, ...defaults, ...options }
: { ...defaults, ...content, ...options }
return handler(mergedOptions)
}
// 消息提示封装
export const toast = {
info: createMessager((opts) => message.info(opts.content, opts), { duration: 3000 }),
success: createMessager((opts) => message.success(opts.content, opts), { duration: 3000 }),
warning: createMessager((opts) => message.warning(opts.content, opts), { duration: 5000 }),
error: createMessager((opts) => message.error(opts.content, opts), { duration: 7000 })
}
// 通知封装
export const notify = {
info: createMessager(notification.info, { title: '提示', duration: 3000 }),
success: createMessager(notification.success, { title: '成功', duration: 3000 }),
warning: createMessager(notification.warning, { title: '警告', duration: 5000 }),
error: createMessager(notification.error, { title: '错误', duration: 7000 })
}
// 对话框封装
export const modal = {
info: (options) => dialog.info(options),
success: (options) => dialog.success(options),
warning: (options) => dialog.warning(options),
error: (options) => dialog.error(options),
confirm: (options) => dialog.confirm(options)
}
// 加载条控制器
export const loader = {
start: () => loadingBar.start(),
finish: () => loadingBar.finish(),
error: () => loadingBar.error(),
setProgress: (progress) => loadingBar.setProgress(progress)
}