From: 小龙 Date: Wed, 22 Jul 2026 05:58:28 +0000 (+0800) Subject: 前端检测+日志去重 v3.4 X-Git-Url: https://szjxzxh.cn/gitweb/avatars/avatar_1.jpg?a=commitdiff_plain;h=14c3ceb4cfad5d03c8d71584dc830d14afd49d44;p=%E5%BE%AE%E4%BF%A1%E7%9B%91%E6%8E%A7 前端检测+日志去重 v3.4 --- diff --git a/wechat_auto_login.py b/wechat_auto_login.py index 8bd13a9..92093a5 100644 --- a/wechat_auto_login.py +++ b/wechat_auto_login.py @@ -372,6 +372,7 @@ try: self._last_login_hash = None self._user_resized = False self._resend_link_sent = False + self._last_logged_status = "" self._setup_ui() @@ -518,6 +519,9 @@ try: # ── 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): @@ -543,6 +547,18 @@ try: 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: @@ -600,8 +616,12 @@ try: 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() @@ -733,8 +753,10 @@ try: 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)