新增功能:启动程序和设置页面添加日志窗口
This commit is contained in:
parent
9295d9f2cf
commit
cae312a272
5 changed files with 55 additions and 53 deletions
|
@ -11,6 +11,8 @@ upgrade_script_name = "upgrade.bat"
|
||||||
|
|
||||||
# 获取最新版本发布信息
|
# 获取最新版本发布信息
|
||||||
get_new_version_url = "https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
get_new_version_url = "https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
||||||
|
# 下载新版本压缩包名
|
||||||
|
file_name = "launcher.7z"
|
||||||
|
|
||||||
# 下载地址
|
# 下载地址
|
||||||
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
|
||||||
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 +10,7 @@ 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 download_git_url, download_python_url, get_new_version_url, upgrade_script_name, \
|
||||||
mirror_list
|
mirror_list, file_name
|
||||||
from launcher.file.download import init_download, download_file
|
from launcher.file.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
|
||||||
|
@ -30,7 +29,7 @@ command_list = {
|
||||||
"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": "..\\python\\pythonw webview_ui.py",
|
||||||
"manager": "start ..\\python\\pythonw manager.py",
|
"manager": "start ..\\python\\pythonw manager.py",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,24 +48,17 @@ 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 = {
|
||||||
for line in iter(text_io.readline, ''):
|
"webview": {"WebSocket客户端建立连接": "mower_ng已成功运行"}
|
||||||
text = line.rstrip('\n').strip()
|
}
|
||||||
custom_event(log_type, text)
|
if command_key in end_keywords:
|
||||||
if output_list is not None:
|
keywords = end_keywords[command_key]
|
||||||
output_list.append(text)
|
for keyword in keywords:
|
||||||
|
if keyword in output:
|
||||||
detected_encoding = 'utf-8'
|
custom_event(LogType.info, keywords[keyword])
|
||||||
text_io = io.TextIOWrapper(stream, encoding=detected_encoding, errors='replace')
|
return True
|
||||||
try:
|
return False
|
||||||
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:
|
||||||
|
@ -91,8 +83,6 @@ class Api:
|
||||||
# 更新启动器本身
|
# 更新启动器本身
|
||||||
def update_self(self, download_url):
|
def update_self(self, 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,8 +134,8 @@ 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):
|
||||||
command = command_list[command]
|
command = command_list[command_key]
|
||||||
if callable(command):
|
if callable(command):
|
||||||
command = command()
|
command = command()
|
||||||
if callable(command):
|
if callable(command):
|
||||||
|
@ -161,18 +151,28 @@ class Api:
|
||||||
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, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=cwd, bufsize=0,
|
||||||
universal_newlines=False
|
universal_newlines=False
|
||||||
) as p:
|
) as p:
|
||||||
stdout_thread = threading.Thread(target=read_stream, args=(p.stdout, LogType.command_out))
|
def process_lines(text_io):
|
||||||
stderr_thread = threading.Thread(target=read_stream,
|
for line in iter(text_io.readline, ''):
|
||||||
args=(p.stderr, LogType.command_out, stdout_stderr))
|
text = line.rstrip('\n').strip()
|
||||||
|
custom_event(LogType.command_out, text)
|
||||||
|
if stdout_stderr is not None:
|
||||||
|
stdout_stderr.append(text)
|
||||||
|
if check_command_end(command_key, text):
|
||||||
|
break
|
||||||
|
|
||||||
stdout_thread.start()
|
detected_encoding = 'utf-8'
|
||||||
stderr_thread.start()
|
text_io = io.TextIOWrapper(p.stdout, encoding=detected_encoding, errors='replace')
|
||||||
|
try:
|
||||||
stdout_thread.join()
|
process_lines(text_io)
|
||||||
stderr_thread.join()
|
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"
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
|
||||||
|
const conf = useConfigStore().config
|
||||||
function webview() {
|
function webview() {
|
||||||
pywebview.api.run('webview', 'mower-ng')
|
pywebview.api.run('webview', 'mower-ng')
|
||||||
}
|
}
|
||||||
|
@ -9,23 +13,16 @@ function manager() {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-flex
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
vertical
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
style="
|
<n-form-item label="启动程序" :label-style="form_item_label_style">
|
||||||
gap: 16px;
|
<n-space size="large">
|
||||||
height: 100%;
|
<n-button class="launch-btn" type="primary" secondary size="large" @click="webview"> 单开运行 </n-button>
|
||||||
padding: 16px;
|
<n-button class="launch-btn" type="primary" secondary size="large" @click="manager"> 多开器 </n-button>
|
||||||
box-sizing: border-box;
|
</n-space>
|
||||||
justify-content: center;
|
</n-form-item>
|
||||||
align-items: center;
|
</n-form>
|
||||||
"
|
<log-component />
|
||||||
>
|
|
||||||
<n-button class="launch-btn" type="primary" secondary size="large" @click="webview">
|
|
||||||
单开运行
|
|
||||||
</n-button>
|
|
||||||
<n-button class="launch-btn" type="primary" secondary size="large" @click="manager">
|
|
||||||
多开器
|
|
||||||
</n-button>
|
|
||||||
</n-flex>
|
</n-flex>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -91,5 +91,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>
|
||||||
|
|
|
@ -3,10 +3,12 @@ import { defineStore } from 'pinia'
|
||||||
export const useConfigStore = defineStore('config', () => {
|
export const useConfigStore = defineStore('config', () => {
|
||||||
class Config {
|
class Config {
|
||||||
constructor(conf) {
|
constructor(conf) {
|
||||||
|
// 整体 Total
|
||||||
this.page = conf.page
|
this.page = conf.page
|
||||||
|
this.is_already_show_doc = conf.is_already_show_doc
|
||||||
|
// 更新代码 UpdatePart
|
||||||
this.branch = conf.branch
|
this.branch = conf.branch
|
||||||
this.mirror = conf.mirror
|
this.mirror = conf.mirror
|
||||||
this.is_already_show_doc = conf.is_already_show_doc
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue