]> 小龙服务器 Git - 微信监控/commitdiff
前端检测+日志去重 v3.4
author小龙 <xl@szjxzxh.cn>
Wed, 22 Jul 2026 05:58:28 +0000 (13:58 +0800)
committer小龙 <xl@szjxzxh.cn>
Wed, 22 Jul 2026 05:58:28 +0000 (13:58 +0800)
wechat_auto_login.py

index 8bd13a961abf9906690616590cf2c16dbc27484b..92093a5625e29f89a0ff92a32bea8f4bc18ac41d 100644 (file)
@@ -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)