self._last_login_hash = None
self._user_resized = False
self._resend_link_sent = False
+ self._last_logged_status = ""
self._setup_ui()
# ── status ──
def _set_status(self, text):
self.status_var.set(text)
+ if text != self._last_logged_status:
+ log.info("状态: %s", text)
+ self._last_logged_status = text
self._update_window_width()
def _update_window_width(self):
self.root.destroy()
log.info("程序退出")
+ def _is_wechat_foreground(self):
+ """检查微信是否在前端(活跃窗口),是则不打断用户操作"""
+ try:
+ fg_hwnd = win32gui.GetForegroundWindow()
+ wechat_wins = _find_wechat_windows()
+ for w in wechat_wins:
+ if hasattr(w, '_hWnd') and w._hWnd == fg_hwnd:
+ return True
+ except Exception:
+ pass
+ return False
+
# ── main loop (every 5 seconds) ──
def _main_loop_tick(self):
if not self.running:
return
# ④ 最小化其他窗口
- _minimize_all_except_wechat()
- time.sleep(0.3)
+ # 微信在前端就不最小化,避免打断用户
+ if not self._is_wechat_foreground():
+ _minimize_all_except_wechat()
+ time.sleep(0.3)
+ else:
+ time.sleep(0.3)
# 再次确认窗口尺寸(最小化后可能有窗口挡住微信)
wechat_windows = _find_wechat_windows()
return
# ④ 截图+哈希比较
- _minimize_all_except_wechat()
- time.sleep(0.3)
+ # 微信在前端就不最小化
+ if not self._is_wechat_foreground():
+ _minimize_all_except_wechat()
+ time.sleep(0.3)
img = _capture_center()
new_md5 = _md5_of_image(img)