diff --git a/monitor.py b/monitor.py index 040a5f6..114d338 100644 --- a/monitor.py +++ b/monitor.py @@ -238,21 +238,19 @@ class MessageMonitor: cls = win32gui.GetClassName(top) title = win32gui.GetWindowText(top) title_upper = title.upper().strip() - # 规则A: Chrome_WidgetWin_1 → QQ NT Electron 主窗口(标题是群名/昵称,不含QQ/TIM) - if "Chrome" in cls: + # _enum_callback 只加了 QQ/TIM 相关窗口,所以 found 里都是有效候选 + # 优先选标题含 QQ/TIM 的(传统模式),其次任何 TXGuiFoundation 或 Chrome 都接受 + if "TIM" in title_upper: + self._app_variant[platform] = "tim" + else: self._app_variant[platform] = "qq_nt" - self._cached_hwnd[platform] = top - self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1] + self._cached_hwnd[platform] = top + self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1] + if "Chrome" in cls: logger.info(f"[{platform}] 窗口已定位(Electron Chrome): {title} top={top}") - return top - # 规则B: 标题含 QQ/TIM → 传统 QQ / TIM 主窗口 - if "QQ" in title_upper or "TIM" in title_upper: - self._app_variant[platform] = "tim" if "TIM" in title_upper else "qq_nt" - self._cached_hwnd[platform] = top - self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1] + else: logger.info(f"[{platform}] 窗口已定位(Win32 Enum): {title} top={top}") - return top - logger.debug(f"[{platform}] Enum 候选跳过: cls={cls} title={title[:30]} top={top}") + return top except Exception: pass # 3. UIA 按窗口名搜索(兜底,可能慢但不挂死)