功能优化: 系统托盘与测试版本构建 1. 系统托盘功能增强 - 添加托盘右键菜单刷新重置功能 - 优化托盘图标显示和管理 - 改进最小化到托盘的处理逻辑 2. 测试版本构建系统 - 新增 testbuild.bat 测试版本构建脚本 - 实现测试版本号自动递增 - 配置测试版本专用输出目录 3. 其他优化 - 优化 SSL 警告全局处理 - 改进加载对话框显示逻辑 - 完善版本号管理机制
This commit is contained in:
@@ -153,33 +153,15 @@ class MainWindow(QMainWindow):
|
||||
# 设置窗口图标
|
||||
icon_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "icon", "two.ico")
|
||||
if os.path.exists(icon_path):
|
||||
window_icon = QIcon(icon_path)
|
||||
if not window_icon.isNull():
|
||||
self.setWindowIcon(window_icon)
|
||||
self.window_icon = QIcon(icon_path)
|
||||
if not self.window_icon.isNull():
|
||||
self.setWindowIcon(self.window_icon)
|
||||
logging.info(f"成功设置窗口图标: {icon_path}")
|
||||
else:
|
||||
logging.warning("图标文件加载失败")
|
||||
|
||||
# 创建系统托盘图标
|
||||
self.tray_icon = QSystemTrayIcon(self)
|
||||
self.tray_icon.setIcon(self.windowIcon())
|
||||
self.tray_icon.setToolTip("听泉Cursor助手")
|
||||
|
||||
# 创建托盘菜单
|
||||
tray_menu = QMenu()
|
||||
show_action = tray_menu.addAction("显示主窗口")
|
||||
show_action.triggered.connect(self.show)
|
||||
quit_action = tray_menu.addAction("退出")
|
||||
quit_action.triggered.connect(QApplication.instance().quit)
|
||||
|
||||
# 设置托盘菜单
|
||||
self.tray_icon.setContextMenu(tray_menu)
|
||||
|
||||
# 连接托盘图标的信号
|
||||
self.tray_icon.activated.connect(self.on_tray_icon_activated)
|
||||
|
||||
# 显示托盘图标
|
||||
self.tray_icon.show()
|
||||
self.create_tray_icon()
|
||||
|
||||
# 创建主窗口部件
|
||||
central_widget = QWidget()
|
||||
@@ -324,24 +306,103 @@ class MainWindow(QMainWindow):
|
||||
# 启动时检查一次状态
|
||||
QTimer.singleShot(0, self.check_status)
|
||||
|
||||
def create_tray_icon(self):
|
||||
"""创建系统托盘图标"""
|
||||
try:
|
||||
# 确保QSystemTrayIcon可用
|
||||
if not QSystemTrayIcon.isSystemTrayAvailable():
|
||||
logging.error("系统托盘不可用")
|
||||
return
|
||||
|
||||
self.tray_icon = QSystemTrayIcon(self)
|
||||
self.tray_icon.setIcon(self.window_icon)
|
||||
self.tray_icon.setToolTip("听泉Cursor助手")
|
||||
|
||||
# 创建托盘菜单
|
||||
self.tray_menu = QMenu() # 保存为实例变量
|
||||
|
||||
# 添加刷新重置按钮
|
||||
refresh_action = self.tray_menu.addAction("刷新重置")
|
||||
refresh_action.triggered.connect(self.refresh_cursor_auth)
|
||||
|
||||
show_action = self.tray_menu.addAction("显示主窗口")
|
||||
show_action.triggered.connect(self.show_and_activate)
|
||||
|
||||
# 添加分隔线
|
||||
self.tray_menu.addSeparator()
|
||||
|
||||
quit_action = self.tray_menu.addAction("退出")
|
||||
quit_action.triggered.connect(self.quit_application)
|
||||
|
||||
# 设置托盘菜单
|
||||
self.tray_icon.setContextMenu(self.tray_menu)
|
||||
|
||||
# 连接托盘图标的信号
|
||||
self.tray_icon.activated.connect(self.on_tray_icon_activated)
|
||||
|
||||
# 显示托盘图标
|
||||
self.tray_icon.show()
|
||||
logging.info("系统托盘图标创建成功")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"创建系统托盘图标失败: {str(e)}")
|
||||
|
||||
def show_and_activate(self):
|
||||
"""显示并激活窗口"""
|
||||
self.show()
|
||||
self.setWindowState(self.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
|
||||
self.activateWindow()
|
||||
self.raise_() # 确保窗口在最前面
|
||||
|
||||
def quit_application(self):
|
||||
"""退出应用程序"""
|
||||
try:
|
||||
# 停止定时器
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
|
||||
# 移除托盘图标
|
||||
if hasattr(self, 'tray_icon'):
|
||||
self.tray_icon.setVisible(False) # 先隐藏托盘图标
|
||||
self.tray_icon.deleteLater() # 删除托盘图标
|
||||
|
||||
# 退出应用程序
|
||||
QApplication.instance().quit()
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"退出应用程序时发生错误: {str(e)}")
|
||||
QApplication.instance().quit()
|
||||
|
||||
def on_tray_icon_activated(self, reason):
|
||||
"""处理托盘图标的点击事件"""
|
||||
if reason == QSystemTrayIcon.DoubleClick:
|
||||
self.show()
|
||||
self.activateWindow()
|
||||
if reason in (QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Trigger):
|
||||
self.show_and_activate()
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""重写关闭事件,最小化到托盘而不是退出"""
|
||||
if hasattr(self, 'tray_icon') and self.tray_icon.isVisible():
|
||||
event.ignore()
|
||||
self.hide()
|
||||
self.tray_icon.showMessage(
|
||||
"听泉Cursor助手",
|
||||
"程序已最小化到系统托盘",
|
||||
QSystemTrayIcon.Information,
|
||||
2000
|
||||
)
|
||||
else:
|
||||
try:
|
||||
if hasattr(self, 'tray_icon') and self.tray_icon.isVisible():
|
||||
event.ignore()
|
||||
self.hide()
|
||||
# 确保托盘图标显示
|
||||
self.tray_icon.show()
|
||||
self.tray_icon.showMessage(
|
||||
"听泉Cursor助手",
|
||||
"程序已最小化到系统托盘",
|
||||
QSystemTrayIcon.Information,
|
||||
2000
|
||||
)
|
||||
else:
|
||||
# 如果托盘图标不可用,则正常退出
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
event.accept()
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"处理关闭事件时发生错误: {str(e)}")
|
||||
# 发生错误时,接受关闭事件
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
event.accept()
|
||||
|
||||
if self._status_timer:
|
||||
|
||||
Reference in New Issue
Block a user