EnumWindows简化: _enum_callback已只加QQ/TIM相关窗口(for+TXGuiFoundation+Chrome+title), for循环直接取第一个可见+尺寸正常的, 不要求标题含QQ/TIM
This commit is contained in:
+10
-12
@@ -238,21 +238,19 @@ class MessageMonitor:
|
|||||||
cls = win32gui.GetClassName(top)
|
cls = win32gui.GetClassName(top)
|
||||||
title = win32gui.GetWindowText(top)
|
title = win32gui.GetWindowText(top)
|
||||||
title_upper = title.upper().strip()
|
title_upper = title.upper().strip()
|
||||||
# 规则A: Chrome_WidgetWin_1 → QQ NT Electron 主窗口(标题是群名/昵称,不含QQ/TIM)
|
# _enum_callback 只加了 QQ/TIM 相关窗口,所以 found 里都是有效候选
|
||||||
if "Chrome" in cls:
|
# 优先选标题含 QQ/TIM 的(传统模式),其次任何 TXGuiFoundation 或 Chrome 都接受
|
||||||
|
if "TIM" in title_upper:
|
||||||
|
self._app_variant[platform] = "tim"
|
||||||
|
else:
|
||||||
self._app_variant[platform] = "qq_nt"
|
self._app_variant[platform] = "qq_nt"
|
||||||
self._cached_hwnd[platform] = top
|
self._cached_hwnd[platform] = top
|
||||||
self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1]
|
self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1]
|
||||||
|
if "Chrome" in cls:
|
||||||
logger.info(f"[{platform}] 窗口已定位(Electron Chrome): {title} top={top}")
|
logger.info(f"[{platform}] 窗口已定位(Electron Chrome): {title} top={top}")
|
||||||
return top
|
else:
|
||||||
# 规则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]
|
|
||||||
logger.info(f"[{platform}] 窗口已定位(Win32 Enum): {title} top={top}")
|
logger.info(f"[{platform}] 窗口已定位(Win32 Enum): {title} top={top}")
|
||||||
return top
|
return top
|
||||||
logger.debug(f"[{platform}] Enum 候选跳过: cls={cls} title={title[:30]} top={top}")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# 3. UIA 按窗口名搜索(兜底,可能慢但不挂死)
|
# 3. UIA 按窗口名搜索(兜底,可能慢但不挂死)
|
||||||
|
|||||||
Reference in New Issue
Block a user