feat(v3.4.7): 重构重置功能和优化重启逻辑

1. 新增 CursorResetter 类,完整封装 cursor_win_id_modifier.ps1 的核心功能

2. 优化 AccountSwitcher 的重启逻辑,避免重复重启

3. 改进进程管理,移除 wmi 依赖,使用 tasklist 替代

4. 提升代码可维护性,后续只需更新 CursorResetter 即可适配脚本变更
This commit is contained in:
huangzhenpc
2025-02-14 15:06:05 +08:00
parent 10523de040
commit 8b2fbef54a
9 changed files with 1322 additions and 437 deletions

View File

@@ -310,6 +310,11 @@ class MainWindow(QMainWindow):
self._activation_status = None # 缓存的激活状态
self._status_timer = None # 状态更新定时器
# 添加心跳定时器
self._heartbeat_timer = QTimer()
self._heartbeat_timer.timeout.connect(self.send_heartbeat)
self._heartbeat_timer.start(5 * 60 * 1000) # 每5分钟发送一次心跳
# 添加请求锁,防止重复提交
self._is_requesting = False
self._last_request_time = 0
@@ -712,7 +717,7 @@ class MainWindow(QMainWindow):
self.show_and_activate()
def closeEvent(self, event):
"""重写关闭事件,最小化到托盘而不是退出"""
"""窗口关闭事件"""
try:
if hasattr(self, 'tray_icon') and self.tray_icon.isVisible():
event.ignore()
@@ -729,6 +734,8 @@ class MainWindow(QMainWindow):
# 如果托盘图标不可用,则正常退出
if self._status_timer:
self._status_timer.stop()
if hasattr(self, '_heartbeat_timer'):
self._heartbeat_timer.stop()
event.accept()
except Exception as e:
@@ -736,12 +743,10 @@ class MainWindow(QMainWindow):
# 发生错误时,接受关闭事件
if self._status_timer:
self._status_timer.stop()
if hasattr(self, '_heartbeat_timer'):
self._heartbeat_timer.stop()
event.accept()
if self._status_timer:
self._status_timer.stop()
super().closeEvent(event)
def copy_device_id(self):
"""复制设备ID到剪贴板"""
QApplication.clipboard().setText(self.hardware_id_edit.text())
@@ -1998,4 +2003,29 @@ class MainWindow(QMainWindow):
layout.addLayout(btn_layout)
msg.setLayout(layout)
msg.exec_()
msg.exec_()
def send_heartbeat(self):
"""发送心跳请求"""
if not self._check_request_throttle():
return
def heartbeat_func():
return self.switcher.send_heartbeat()
# 创建工作线程
self.heartbeat_worker = ApiWorker(heartbeat_func)
self.heartbeat_worker.finished.connect(self.on_heartbeat_complete)
self.heartbeat_worker.start()
def on_heartbeat_complete(self, result):
"""心跳完成回调"""
success, message = result
self._request_complete()
if success:
logging.info(f"心跳发送成功: {message}")
# 更新状态显示
self.check_status()
else:
logging.error(f"心跳发送失败: {message}")