[patch] 新增自动更新功能 模块 优化进度条显示 横幅图片资源上传
This commit is contained in:
152
main.py
152
main.py
@@ -1468,66 +1468,63 @@ class LoginWindow(QMainWindow):
|
||||
try:
|
||||
self.add_log(f"✅ 下载完成: {installer_path}", "SUCCESS")
|
||||
|
||||
# 更新进度对话框状态
|
||||
# 🎯 更新进度对话框到UAC等待阶段(不关闭对话框)
|
||||
progress_dialog.download_finished(installer_path)
|
||||
|
||||
# 延迟1秒,让用户看到"下载完成"提示
|
||||
QTimer.singleShot(1000, lambda: self.prepare_install(installer_path, progress_dialog))
|
||||
# 延迟2秒,让用户看到"下载完成"提示,然后自动开始安装
|
||||
QTimer.singleShot(2000, lambda: self.prepare_install(installer_path, progress_dialog))
|
||||
|
||||
except Exception as e:
|
||||
self.add_log(f"处理下载完成事件失败: {e}", "ERROR")
|
||||
|
||||
def prepare_install(self, installer_path, progress_dialog):
|
||||
"""准备安装"""
|
||||
"""准备安装(不再弹窗询问,直接开始)"""
|
||||
try:
|
||||
# 关闭进度对话框
|
||||
progress_dialog.accept()
|
||||
# 🔥 不再关闭进度对话框,也不再弹窗询问,直接开始安装
|
||||
self.add_log("开始执行自动安装流程", "INFO")
|
||||
|
||||
# 提示即将安装
|
||||
reply = QMessageBox.information(
|
||||
self,
|
||||
"准备安装",
|
||||
"新版本下载完成!\n\n"
|
||||
"程序将自动退出并安装新版本,\n"
|
||||
"安装完成后会自动重启。\n\n"
|
||||
"是否立即安装?",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.Yes
|
||||
)
|
||||
from auto_updater import install_update_and_restart
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
from auto_updater import install_update_and_restart
|
||||
# 🔥 启动静默安装(带UAC提升)
|
||||
result = install_update_and_restart(installer_path)
|
||||
|
||||
if result:
|
||||
# ✅ 用户授权成功,脚本已启动(但在等待GUI退出)
|
||||
self.add_log("✅ 用户已授权UAC,更新脚本已启动", "SUCCESS")
|
||||
self.add_log("进度条将执行到100%后提示用户", "INFO")
|
||||
|
||||
# 启动静默安装(带自动重启)
|
||||
if install_update_and_restart(installer_path):
|
||||
self.add_log("✅ 更新安装已启动,程序即将退出", "SUCCESS")
|
||||
self.add_log("程序将在安装完成后自动重启", "INFO")
|
||||
|
||||
# 显示提示
|
||||
QMessageBox.information(
|
||||
self,
|
||||
"正在更新",
|
||||
"程序即将退出并开始安装。\n\n"
|
||||
"安装完成后会自动重启,请稍候...",
|
||||
QMessageBox.Ok
|
||||
)
|
||||
|
||||
# 延迟1秒后退出(让用户看到提示)
|
||||
QTimer.singleShot(1000, self.quit_for_update)
|
||||
else:
|
||||
self.add_log("❌ 启动安装失败", "ERROR")
|
||||
QMessageBox.critical(
|
||||
self,
|
||||
"安装失败",
|
||||
"无法启动安装程序,请手动运行安装包:\n\n" + installer_path,
|
||||
QMessageBox.Ok
|
||||
)
|
||||
# 🎯 更新进度对话框到UAC授权完成阶段
|
||||
progress_dialog.uac_authorized()
|
||||
|
||||
# 🔥 新增:等待进度条执行到100%后再处理
|
||||
# 通过定时器循环检查进度是否到100%
|
||||
self.progress_check_timer = QTimer()
|
||||
|
||||
def check_progress_complete():
|
||||
if progress_dialog.restart_progress >= 100:
|
||||
# 进度已到100%,停止检查并弹窗询问用户
|
||||
self.progress_check_timer.stop()
|
||||
self.show_update_complete_dialog(progress_dialog)
|
||||
|
||||
self.progress_check_timer.timeout.connect(check_progress_complete)
|
||||
self.progress_check_timer.start(1000) # 每1秒检查一次
|
||||
else:
|
||||
self.add_log("用户取消安装", "INFO")
|
||||
QMessageBox.information(
|
||||
# ⚠️ 用户取消了UAC授权,或启动失败
|
||||
self.add_log("⚠️ 更新已取消(用户取消UAC授权或启动失败)", "WARNING")
|
||||
|
||||
# 关闭进度对话框
|
||||
progress_dialog.reject()
|
||||
|
||||
# 显示友好提示
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"安装包已保存",
|
||||
f"安装包已保存到:\n{installer_path}\n\n您可以稍后手动运行安装。",
|
||||
"更新已取消",
|
||||
"未能启动自动更新。\n\n"
|
||||
"可能原因:\n"
|
||||
"• 您取消了管理员权限授权\n"
|
||||
"• 系统安全策略限制\n\n"
|
||||
f"安装包已保存到:\n{installer_path}\n\n"
|
||||
"您可以稍后手动运行安装包进行更新。",
|
||||
QMessageBox.Ok
|
||||
)
|
||||
|
||||
@@ -1535,6 +1532,9 @@ class LoginWindow(QMainWindow):
|
||||
self.add_log(f"准备安装失败: {e}", "ERROR")
|
||||
import traceback
|
||||
self.add_log(f"详细错误: {traceback.format_exc()}", "ERROR")
|
||||
|
||||
# 关闭进度对话框
|
||||
progress_dialog.reject()
|
||||
|
||||
def on_download_error(self, error_msg, progress_dialog, download_url, latest_version):
|
||||
"""下载失败处理"""
|
||||
@@ -1571,6 +1571,64 @@ class LoginWindow(QMainWindow):
|
||||
except Exception as e:
|
||||
self.add_log(f"处理下载失败异常: {e}", "ERROR")
|
||||
|
||||
def show_update_complete_dialog(self, progress_dialog):
|
||||
"""显示更新完成对话框,询问是否立即启动"""
|
||||
try:
|
||||
self.add_log("🎉 更新流程已完成,准备提示用户", "SUCCESS")
|
||||
|
||||
# 清理检查定时器
|
||||
if hasattr(self, 'progress_check_timer') and self.progress_check_timer:
|
||||
self.progress_check_timer.stop()
|
||||
self.progress_check_timer = None
|
||||
|
||||
# 🔥 不立即关闭进度对话框,先弹窗询问用户
|
||||
# 弹窗询问用户
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"更新完成",
|
||||
"🎉 恭喜!新版本安装成功!\n\n"
|
||||
"是否立即启动新版本?\n\n"
|
||||
"• 点击「是」:立即启动新版本\n"
|
||||
"• 点击「否」:稍后手动启动",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.Yes
|
||||
)
|
||||
|
||||
# 关闭进度对话框
|
||||
progress_dialog.accept()
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.add_log("✅ 用户选择立即启动新版本", "INFO")
|
||||
self.add_log("🚀 程序立即退出,让批处理脚本完成安装", "INFO")
|
||||
# 立即退出,让批处理脚本启动新版本(无延迟)
|
||||
QApplication.instance().quit()
|
||||
else:
|
||||
self.add_log("ℹ️ 用户选择稍后手动启动", "INFO")
|
||||
# 用户选择稍后启动,显示提示后退出
|
||||
QMessageBox.information(
|
||||
self,
|
||||
"提示",
|
||||
"程序即将退出。\n\n"
|
||||
"您可以随时从开始菜单或桌面快捷方式\n"
|
||||
"启动新版本的水滴AI客服智能助手。",
|
||||
QMessageBox.Ok
|
||||
)
|
||||
self.add_log("🚀 程序退出", "INFO")
|
||||
# 立即退出(无延迟)
|
||||
QApplication.instance().quit()
|
||||
|
||||
except Exception as e:
|
||||
self.add_log(f"❌ 显示更新完成对话框失败: {e}", "ERROR")
|
||||
import traceback
|
||||
self.add_log(f"详细错误: {traceback.format_exc()}", "ERROR")
|
||||
# 关闭进度对话框
|
||||
try:
|
||||
progress_dialog.reject()
|
||||
except:
|
||||
pass
|
||||
# 出错也要立即退出
|
||||
QApplication.instance().quit()
|
||||
|
||||
def quit_for_update(self):
|
||||
"""为更新而退出程序"""
|
||||
self.add_log("正在退出程序以进行更新...", "INFO")
|
||||
|
||||
Reference in New Issue
Block a user