初步实现提示用户更新
This commit is contained in:
41
main.py
41
main.py
@@ -42,6 +42,9 @@ class LoginWindow(QMainWindow):
|
||||
# 日志管理相关变量已删除
|
||||
|
||||
self.initUI()
|
||||
|
||||
# 延迟设置版本检查器,确保WebSocket连接已建立
|
||||
QTimer.singleShot(5000, self.setup_version_checker)
|
||||
|
||||
def initUI(self):
|
||||
# 设置窗口基本属性
|
||||
@@ -699,6 +702,44 @@ class LoginWindow(QMainWindow):
|
||||
self.quit_application()
|
||||
event.accept()
|
||||
|
||||
def setup_version_checker(self):
|
||||
"""设置版本检查器的GUI回调"""
|
||||
try:
|
||||
from WebSocket.backend_singleton import get_websocket_manager
|
||||
ws_manager = get_websocket_manager()
|
||||
if ws_manager:
|
||||
ws_manager.gui_update_callback = self.show_update_notification
|
||||
self.add_log("✅ 版本检查器GUI回调已设置", "SUCCESS")
|
||||
else:
|
||||
self.add_log("⚠️ WebSocket管理器未初始化", "WARNING")
|
||||
except Exception as e:
|
||||
self.add_log(f"❌ 设置版本检查器失败: {e}", "ERROR")
|
||||
|
||||
def show_update_notification(self, latest_version, download_url):
|
||||
"""显示版本更新通知"""
|
||||
try:
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"版本更新",
|
||||
f"发现新版本 {latest_version},是否立即更新?\n\n点击确定将打开下载页面。",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.Yes
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.trigger_update(download_url)
|
||||
except Exception as e:
|
||||
self.add_log(f"❌ 显示更新通知失败: {e}", "ERROR")
|
||||
|
||||
def trigger_update(self, download_url):
|
||||
"""触发更新下载"""
|
||||
import webbrowser
|
||||
try:
|
||||
webbrowser.open(download_url)
|
||||
self.add_log("✅ 已打开更新下载页面", "SUCCESS")
|
||||
except Exception as e:
|
||||
self.add_log(f"❌ 打开下载页面失败: {e}", "ERROR")
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数,用于测试界面"""
|
||||
|
||||
Reference in New Issue
Block a user