格式化部分代码
This commit is contained in:
parent
988924ed3a
commit
01c4bee95e
1 changed files with 13 additions and 8 deletions
21
launcher.py
21
launcher.py
|
@ -2,13 +2,14 @@ import json
|
|||
import mimetypes
|
||||
from pathlib import Path
|
||||
from shutil import rmtree
|
||||
from subprocess import PIPE, STDOUT, Popen
|
||||
from subprocess import CREATE_NO_WINDOW, PIPE, STDOUT, Popen
|
||||
|
||||
import requests
|
||||
import webview
|
||||
|
||||
from log import logger
|
||||
from python.Lib import shutil, os, subprocess
|
||||
import shutil
|
||||
import os
|
||||
|
||||
mimetypes.add_type("text/html", ".html")
|
||||
mimetypes.add_type("text/css", ".css")
|
||||
|
@ -23,7 +24,9 @@ config = {
|
|||
}
|
||||
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"
|
||||
|
||||
|
@ -95,7 +98,7 @@ class Api:
|
|||
logger.info(f"下载新版本: {download_url}到{download_path}")
|
||||
response = requests.get(download_url, stream=True)
|
||||
if response.status_code == 200:
|
||||
with open(download_path, 'wb') as file:
|
||||
with open(download_path, "wb") as file:
|
||||
shutil.copyfileobj(response.raw, file)
|
||||
logger.info("下载完成")
|
||||
else:
|
||||
|
@ -105,7 +108,7 @@ class Api:
|
|||
script_path = os.path.join(os.getcwd(), upgrade_script_name)
|
||||
folder_path = os.path.join(os.getcwd(), "_internal")
|
||||
exe_path = os.path.join(os.getcwd(), "launcher.exe")
|
||||
with open(script_path, 'w') as b:
|
||||
with open(script_path, "w") as b:
|
||||
TempList = f"@echo off\n"
|
||||
TempList += f"timeout /t 3 /nobreak\n" # 等待进程退出
|
||||
TempList += f"rmdir {folder_path}\n" # 删除_internal
|
||||
|
@ -117,7 +120,7 @@ class Api:
|
|||
TempList += f"exit"
|
||||
b.write(TempList)
|
||||
# 不显示cmd窗口
|
||||
subprocess.Popen([script_path], creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
Popen([script_path], creationflags=CREATE_NO_WINDOW)
|
||||
os._exit(0)
|
||||
|
||||
def rm_site_packages(self):
|
||||
|
@ -141,7 +144,7 @@ class Api:
|
|||
custom_event(command + "\n")
|
||||
try:
|
||||
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:
|
||||
for data in p.stdout:
|
||||
try:
|
||||
|
@ -160,7 +163,9 @@ class Api:
|
|||
if Path(upgrade_script_name).exists():
|
||||
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())
|
||||
webview.start()
|
||||
|
||||
|
|
Loading…
Reference in a new issue