功能优化: 系统托盘与测试版本构建 1. 系统托盘功能增强 - 添加托盘右键菜单刷新重置功能 - 优化托盘图标显示和管理 - 改进最小化到托盘的处理逻辑 2. 测试版本构建系统 - 新增 testbuild.bat 测试版本构建脚本 - 实现测试版本号自动递增 - 配置测试版本专用输出目录 3. 其他优化 - 优化 SSL 警告全局处理 - 改进加载对话框显示逻辑 - 完善版本号管理机制
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -17,4 +17,6 @@ venv/
|
|||||||
env/
|
env/
|
||||||
|
|
||||||
# Local development settings
|
# Local development settings
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
testversion.txt
|
||||||
@@ -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")
|
icon_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "icon", "two.ico")
|
||||||
if os.path.exists(icon_path):
|
if os.path.exists(icon_path):
|
||||||
window_icon = QIcon(icon_path)
|
self.window_icon = QIcon(icon_path)
|
||||||
if not window_icon.isNull():
|
if not self.window_icon.isNull():
|
||||||
self.setWindowIcon(window_icon)
|
self.setWindowIcon(self.window_icon)
|
||||||
logging.info(f"成功设置窗口图标: {icon_path}")
|
logging.info(f"成功设置窗口图标: {icon_path}")
|
||||||
else:
|
else:
|
||||||
logging.warning("图标文件加载失败")
|
logging.warning("图标文件加载失败")
|
||||||
|
|
||||||
# 创建系统托盘图标
|
# 创建系统托盘图标
|
||||||
self.tray_icon = QSystemTrayIcon(self)
|
self.create_tray_icon()
|
||||||
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()
|
|
||||||
|
|
||||||
# 创建主窗口部件
|
# 创建主窗口部件
|
||||||
central_widget = QWidget()
|
central_widget = QWidget()
|
||||||
@@ -324,24 +306,103 @@ class MainWindow(QMainWindow):
|
|||||||
# 启动时检查一次状态
|
# 启动时检查一次状态
|
||||||
QTimer.singleShot(0, self.check_status)
|
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):
|
def on_tray_icon_activated(self, reason):
|
||||||
"""处理托盘图标的点击事件"""
|
"""处理托盘图标的点击事件"""
|
||||||
if reason == QSystemTrayIcon.DoubleClick:
|
if reason in (QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Trigger):
|
||||||
self.show()
|
self.show_and_activate()
|
||||||
self.activateWindow()
|
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
"""重写关闭事件,最小化到托盘而不是退出"""
|
"""重写关闭事件,最小化到托盘而不是退出"""
|
||||||
if hasattr(self, 'tray_icon') and self.tray_icon.isVisible():
|
try:
|
||||||
event.ignore()
|
if hasattr(self, 'tray_icon') and self.tray_icon.isVisible():
|
||||||
self.hide()
|
event.ignore()
|
||||||
self.tray_icon.showMessage(
|
self.hide()
|
||||||
"听泉Cursor助手",
|
# 确保托盘图标显示
|
||||||
"程序已最小化到系统托盘",
|
self.tray_icon.show()
|
||||||
QSystemTrayIcon.Information,
|
self.tray_icon.showMessage(
|
||||||
2000
|
"听泉Cursor助手",
|
||||||
)
|
"程序已最小化到系统托盘",
|
||||||
else:
|
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()
|
event.accept()
|
||||||
|
|
||||||
if self._status_timer:
|
if self._status_timer:
|
||||||
|
|||||||
16
main.py
16
main.py
@@ -60,6 +60,15 @@ def main():
|
|||||||
# 创建QApplication实例
|
# 创建QApplication实例
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
# 检查系统托盘是否可用
|
||||||
|
if not QSystemTrayIcon.isSystemTrayAvailable():
|
||||||
|
logging.error("系统托盘不可用")
|
||||||
|
QMessageBox.critical(None, "错误", "系统托盘不可用,程序无法正常运行。")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# 设置应用程序不会在最后一个窗口关闭时退出
|
||||||
|
app.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
||||||
# 检查Python版本
|
# 检查Python版本
|
||||||
@@ -103,7 +112,8 @@ def main():
|
|||||||
|
|
||||||
logging.info("正在启动主窗口...")
|
logging.info("正在启动主窗口...")
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec_())
|
|
||||||
|
return app.exec_()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"程序运行出错: {str(e)}\n{traceback.format_exc()}"
|
error_msg = f"程序运行出错: {str(e)}\n{traceback.format_exc()}"
|
||||||
@@ -112,7 +122,7 @@ def main():
|
|||||||
if QApplication.instance() is None:
|
if QApplication.instance() is None:
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
QMessageBox.critical(None, "错误", error_msg)
|
QMessageBox.critical(None, "错误", error_msg)
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
sys.exit(main())
|
||||||
51
testbuild.bat
Normal file
51
testbuild.bat
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
setlocal EnableDelayedExpansion
|
||||||
|
|
||||||
|
REM 激活虚拟环境
|
||||||
|
call venv\Scripts\activate.bat
|
||||||
|
|
||||||
|
REM 确保安装了必要的包
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
REM 读取当前版本号
|
||||||
|
set /p VERSION=<version.txt
|
||||||
|
echo 当前正式版本: %VERSION%
|
||||||
|
|
||||||
|
REM 读取测试版本号(如果存在)
|
||||||
|
if exist testversion.txt (
|
||||||
|
set /p TEST_VERSION=<testversion.txt
|
||||||
|
) else (
|
||||||
|
set TEST_VERSION=0
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 增加测试版本号
|
||||||
|
set /a TEST_VERSION+=1
|
||||||
|
echo !TEST_VERSION!>testversion.txt
|
||||||
|
echo 测试版本号: !TEST_VERSION!
|
||||||
|
|
||||||
|
REM 组合完整版本号
|
||||||
|
set FULL_VERSION=%VERSION%.!TEST_VERSION!
|
||||||
|
echo 完整版本号: !FULL_VERSION!
|
||||||
|
|
||||||
|
REM 创建测试版本输出目录
|
||||||
|
if not exist "dist\test" mkdir "dist\test"
|
||||||
|
|
||||||
|
REM 清理旧文件
|
||||||
|
if exist "dist\听泉cursor助手%VERSION%.exe" del "dist\听泉cursor助手%VERSION%.exe"
|
||||||
|
if exist "build" rmdir /s /q "build"
|
||||||
|
|
||||||
|
REM 执行打包
|
||||||
|
venv\Scripts\python.exe -m PyInstaller build_nezha.spec --clean
|
||||||
|
|
||||||
|
REM 移动并重命名文件
|
||||||
|
move "dist\听泉cursor助手%VERSION%.exe" "dist\test\听泉cursor助手v!FULL_VERSION!.exe"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo 测试版本构建完成!
|
||||||
|
echo 版本号: v!FULL_VERSION!
|
||||||
|
echo 文件位置: dist\test\听泉cursor助手v!FULL_VERSION!.exe
|
||||||
|
|
||||||
|
REM 退出虚拟环境
|
||||||
|
deactivate
|
||||||
|
pause
|
||||||
@@ -1 +1 @@
|
|||||||
3.3.9
|
3.4.0
|
||||||
Reference in New Issue
Block a user