fix: 修复插件卸载后重启失败问题,增加安装进度日志
This commit is contained in:
@@ -13,6 +13,8 @@ Model Team Tools - 主程序入口
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
import runtime_hook # noqa: F401 启动时把 plugins/*/ 加进 sys.path,必须在 core 之前
|
||||
import core
|
||||
import traceback
|
||||
import importlib
|
||||
@@ -20,7 +22,7 @@ import importlib
|
||||
from pathlib import Path
|
||||
|
||||
from typing import Optional
|
||||
from PySide6.QtCore import QProcess, QTimer
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtGui import QIcon,QAction
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QMenuBar, QStatusBar
|
||||
from qt_material import apply_stylesheet
|
||||
@@ -159,25 +161,39 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
def _restart_app(self) -> None:
|
||||
"""启动新进程并退出当前进程。
|
||||
|
||||
sys.executable + sys.argv 同时兼容开发模式(python.exe main.py)
|
||||
与打包模式(main.exe)。
|
||||
开发模式:python.exe main.py
|
||||
打包模式:main.exe(Nuitka standalone)
|
||||
|
||||
用 subprocess.Popen + DETACHED_PROCESS 直接调 Win32 CreateProcess。
|
||||
Nuitka standalone 下 sys.executable 指向不存在的原始 python.exe,
|
||||
此时改用 sys.argv[0](即 main.exe 自身)。
|
||||
"""
|
||||
work_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
|
||||
# 【重要】添加防递归标记,防止新进程启动后再次触发重启逻辑
|
||||
|
||||
args = sys.argv[:]
|
||||
if '--restarting' not in args:
|
||||
args.append('--restarting')
|
||||
|
||||
# 启动新进程
|
||||
pid = QProcess.startDetached(sys.executable, args, work_dir)
|
||||
|
||||
if pid:
|
||||
print(f"新进程启动成功 (PID: {pid}),准备退出当前进程...")
|
||||
# ✅ 关键修复:延迟 300ms 退出,确保新进程彻底“断奶”
|
||||
QTimer.singleShot(300, QApplication.quit)
|
||||
|
||||
# Nuitka standalone 下 sys.executable 指向编译机器的 python.exe(分发环境不存在),
|
||||
# 直接用 os.path.isfile 检测,不存在时回退到 sys.argv[0](main.exe 自身)。
|
||||
if os.path.isfile(sys.executable):
|
||||
cmd = [sys.executable] + args
|
||||
else:
|
||||
print("重启失败,请检查路径或权限")
|
||||
cmd = [os.path.abspath(sys.argv[0])] + args[1:]
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
cwd=work_dir,
|
||||
creationflags=subprocess.DETACHED_PROCESS,
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
logger.info(f"新进程已启动 (PID: {proc.pid}),当前进程即将退出")
|
||||
QTimer.singleShot(100, QApplication.quit)
|
||||
except Exception as e:
|
||||
logger.error(f"启动新进程失败: {e}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user