删除自更新多余代码,ruff格式化代码
This commit is contained in:
parent
d1b3d34c7a
commit
7fbbc088ae
2 changed files with 21 additions and 42 deletions
61
launcher.py
61
launcher.py
|
@ -1,6 +1,5 @@
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import platform
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
@ -27,6 +26,8 @@ config_path = Path("launcher.json")
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
|
upgrade_script_name = "upgrade.bat"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with config_path.open("r") as f:
|
with config_path.open("r") as f:
|
||||||
user_config = json.load(f)
|
user_config = json.load(f)
|
||||||
|
@ -40,42 +41,23 @@ def custom_event(data):
|
||||||
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
|
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
|
||||||
window.evaluate_js(js)
|
window.evaluate_js(js)
|
||||||
|
|
||||||
|
|
||||||
def replace_restart(exename, new_exename):
|
def replace_restart(exename, new_exename):
|
||||||
script_name = "upgrade.sh" if platform.system() != "Windows" else "upgrade.bat"
|
script_path = os.path.join(os.getcwd(), upgrade_script_name)
|
||||||
script_path = os.path.join(os.getcwd(), script_name)
|
|
||||||
|
|
||||||
with open(script_path, 'w') as b:
|
with open(script_path, 'w') as b:
|
||||||
if platform.system() == "Windows":
|
TempList = f"@echo off\n"
|
||||||
TempList = f"@echo off\n"
|
TempList += f"timeout /t 3 /nobreak\n" # 等待进程退出
|
||||||
TempList += f"timeout /t 3 /nobreak\n" # 等待进程退出
|
TempList += f"del {exename}\n" # 删除旧程序
|
||||||
TempList += f"del {exename}\n" # 删除旧程序
|
TempList += f"move {new_exename} {exename}\n" # 复制新版本程序
|
||||||
TempList += f"move {new_exename} {exename}\n" # 复制新版本程序
|
TempList += f"timeout /t 1 /nobreak\n" # 等待复制完成
|
||||||
TempList += f"timeout /t 1 /nobreak\n" # 等待复制完成
|
TempList += f"start {exename}\n" # 启动新程序
|
||||||
TempList += f"start {exename}\n" # 启动新程序
|
TempList += f"exit"
|
||||||
TempList += f"exit"
|
|
||||||
else:
|
|
||||||
TempList = f"#!/bin/sh\n"
|
|
||||||
TempList += f"EXENAME={exename}\n"
|
|
||||||
TempList += f"NEW_EXENAME={new_exename}\n"
|
|
||||||
TempList += f"sleep 3\n"
|
|
||||||
TempList += f"rm \"$EXENAME\"\n"
|
|
||||||
TempList += f"mv \"$NEW_EXENAME\" \"$EXENAME\"\n"
|
|
||||||
TempList += f"sleep 1\n"
|
|
||||||
TempList += f"nohup ./{exename} &\n"
|
|
||||||
TempList += f"exit 0\n"
|
|
||||||
b.write(TempList)
|
b.write(TempList)
|
||||||
|
# 不显示cmd窗口
|
||||||
if platform.system() != "Windows":
|
subprocess.Popen([script_path], creationflags=subprocess.CREATE_NO_WINDOW)
|
||||||
os.chmod(script_path, 0o755) # 设置脚本可执行权限
|
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
|
||||||
# 不显示cmd窗口
|
|
||||||
subprocess.Popen([script_path], creationflags=subprocess.CREATE_NO_WINDOW)
|
|
||||||
else:
|
|
||||||
subprocess.Popen([script_path, exename, new_exename])
|
|
||||||
|
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
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/",
|
||||||
|
@ -83,7 +65,6 @@ mirror_list = {
|
||||||
"sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple",
|
"sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
command_list = {
|
command_list = {
|
||||||
"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",
|
||||||
|
@ -125,7 +106,7 @@ class Api:
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
# 更新启动器本身
|
# 更新启动器本身
|
||||||
def update_self(self,download_url):
|
def update_self(self, download_url):
|
||||||
# 获取当前启动器的路径
|
# 获取当前启动器的路径
|
||||||
current_path = sys.argv[0]
|
current_path = sys.argv[0]
|
||||||
# 如果current_path是以py结尾,则将其转换为.exe
|
# 如果current_path是以py结尾,则将其转换为.exe
|
||||||
|
@ -143,7 +124,7 @@ class Api:
|
||||||
return f"下载新版本: {response.status_code}"
|
return f"下载新版本: {response.status_code}"
|
||||||
|
|
||||||
logger.info(f"替换旧版本,{temp_path} -> {current_path}")
|
logger.info(f"替换旧版本,{temp_path} -> {current_path}")
|
||||||
replace_restart(current_path,temp_path)
|
replace_restart(current_path, temp_path)
|
||||||
|
|
||||||
def rm_site_packages(self):
|
def rm_site_packages(self):
|
||||||
site_packages_path = Path("./python/Lib/site-packages")
|
site_packages_path = Path("./python/Lib/site-packages")
|
||||||
|
@ -166,7 +147,7 @@ class Api:
|
||||||
custom_event(command + "\n")
|
custom_event(command + "\n")
|
||||||
try:
|
try:
|
||||||
with Popen(
|
with Popen(
|
||||||
command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0
|
command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0
|
||||||
) as p:
|
) as p:
|
||||||
for data in p.stdout:
|
for data in p.stdout:
|
||||||
try:
|
try:
|
||||||
|
@ -180,13 +161,13 @@ class Api:
|
||||||
custom_event(str(e))
|
custom_event(str(e))
|
||||||
return "failed"
|
return "failed"
|
||||||
|
|
||||||
script_name = "upgrade.sh" if platform.system() != "Windows" else "upgrade.bat"
|
|
||||||
# 如果当前路径存在更新脚本,则删除
|
# 如果当前路径存在更新脚本,则删除
|
||||||
if Path(script_name).exists():
|
if Path(upgrade_script_name).exists():
|
||||||
os.remove(script_name)
|
os.remove(upgrade_script_name)
|
||||||
|
|
||||||
window = webview.create_window(f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api())
|
window = webview.create_window(f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api())
|
||||||
#window = webview.create_window(f"mower-ng launcher {version}", "http://localhost:5173/", js_api=Api())
|
# window = webview.create_window(f"mower-ng launcher {version}", "http://localhost:5173/", js_api=Api())
|
||||||
webview.start()
|
webview.start()
|
||||||
|
|
||||||
with config_path.open("w") as f:
|
with config_path.open("w") as f:
|
||||||
|
|
|
@ -8,8 +8,6 @@ const running = inject('running')
|
||||||
const version = inject('version')
|
const version = inject('version')
|
||||||
const new_version = inject('new_version')
|
const new_version = inject('new_version')
|
||||||
|
|
||||||
const branch = ref(null)
|
|
||||||
const mirror = ref(null)
|
|
||||||
const check_running = ref(false)
|
const check_running = ref(false)
|
||||||
const update_self_running = ref(false)
|
const update_self_running = ref(false)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue