diff --git a/.gitignore b/.gitignore index 4a61a32..e32caef 100644 --- a/.gitignore +++ b/.gitignore @@ -163,6 +163,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ +launcher.iml # Mower-ng git/ diff --git a/README.md b/README.md index a43125d..5f04d6a 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,11 @@ 前端运行 `npm run build` 生成 `ui/dist`,之后安装 PyInstaller,运行 ```bash -pyinstaller -w -F --add-data ui/dist:ui/dist launcher.py +pyinstaller -w --add-data ui/dist:ui/dist launcher.py +``` + +在dist文件夹生成launcher文件夹,切到dist文件夹下运行 + +```bash +tar -cf launcher.tar launcher ``` diff --git a/launcher.py b/launcher.py index 8df7c24..700b7cc 100644 --- a/launcher.py +++ b/launcher.py @@ -1,6 +1,5 @@ import json import mimetypes -import sys from pathlib import Path from shutil import rmtree from subprocess import PIPE, STDOUT, Popen @@ -15,7 +14,7 @@ mimetypes.add_type("text/html", ".html") mimetypes.add_type("text/css", ".css") mimetypes.add_type("application/javascript", ".js") -version = "V0.2" +version = "v0.2" config = { "page": "init", @@ -42,22 +41,6 @@ def custom_event(data): window.evaluate_js(js) -def replace_restart(exename, new_exename): - script_path = os.path.join(os.getcwd(), upgrade_script_name) - with open(script_path, 'w') as b: - TempList = f"@echo off\n" - TempList += f"timeout /t 3 /nobreak\n" # 等待进程退出 - TempList += f"del {exename}\n" # 删除旧程序 - TempList += f"move {new_exename} {exename}\n" # 复制新版本程序 - TempList += f"timeout /t 1 /nobreak\n" # 等待复制完成 - TempList += f"start {exename}\n" # 启动新程序 - TempList += f"exit" - b.write(TempList) - # 不显示cmd窗口 - subprocess.Popen([script_path], creationflags=subprocess.CREATE_NO_WINDOW) - os._exit(0) - - mirror_list = { "pypi": "https://pypi.org/simple", "aliyun": "https://mirrors.aliyun.com/pypi/simple/", @@ -107,24 +90,35 @@ class Api: # 更新启动器本身 def update_self(self, download_url): - # 获取当前启动器的路径 - current_path = sys.argv[0] - # 如果current_path是以py结尾,则将其转换为.exe - if current_path.endswith(".py"): - current_path = current_path[:-3] + ".exe" - temp_path = current_path + '.tmp' - - logger.info(f"下载新版本: {download_url}") + # 下载压缩包的全路径 + download_path = os.path.join(os.getcwd(), os.path.basename(download_url)) + logger.info(f"下载新版本: {download_url}到{download_path}") response = requests.get(download_url, stream=True) if response.status_code == 200: - with open(temp_path, 'wb') as file: + with open(download_path, 'wb') as file: shutil.copyfileobj(response.raw, file) + logger.info("下载完成") else: logger.error(f"下载新版本失败: {response.status_code}") - return f"下载新版本: {response.status_code}" + return f"下载新版本失败: {response.status_code}" - logger.info(f"替换旧版本,{temp_path} -> {current_path}") - replace_restart(current_path, temp_path) + 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: + TempList = f"@echo off\n" + TempList += f"timeout /t 3 /nobreak\n" # 等待进程退出 + TempList += f"rmdir {folder_path}\n" # 删除_internal + TempList += f"del {exe_path}\n" # 删除exe + TempList += f"tar -xf {download_path} -C ..\n" # 解压压缩包 + TempList += f"timeout /t 1 /nobreak\n" # 等待解压 + TempList += f"start {exe_path}\n" # 启动新程序 + TempList += f"del {download_path}\n" # 删除压缩包 + TempList += f"exit" + b.write(TempList) + # 不显示cmd窗口 + subprocess.Popen([script_path], creationflags=subprocess.CREATE_NO_WINDOW) + os._exit(0) def rm_site_packages(self): site_packages_path = Path("./python/Lib/site-packages") diff --git a/ui/src/pages/Settings.vue b/ui/src/pages/Settings.vue index cfe9d61..cd21d17 100644 --- a/ui/src/pages/Settings.vue +++ b/ui/src/pages/Settings.vue @@ -75,7 +75,7 @@ async function check_update() {