fix(desktop-wake): n2-wake wecom_search via main WeWorkWindow hwnd (1.2.7)
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 27s
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 27s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -15,7 +15,13 @@ from .probe import probe
|
||||
from .profiles import load_profile
|
||||
from .types import Profile, WakeStepResult
|
||||
from . import uia_backend
|
||||
from .window import activate_hwnd, find_hwnd_for_profile, require_windows
|
||||
from .window import (
|
||||
activate_hwnd,
|
||||
find_hwnd_for_profile,
|
||||
find_same_pid_hwnd_by_class,
|
||||
get_window_pid,
|
||||
require_windows,
|
||||
)
|
||||
|
||||
_logger = logging.getLogger("jiangchang_desktop_wake.wake")
|
||||
|
||||
@@ -23,6 +29,48 @@ _logger = logging.getLogger("jiangchang_desktop_wake.wake")
|
||||
StrategyFn = Callable[[int, Profile], Tuple[str, str]]
|
||||
|
||||
|
||||
def resolve_native_hwnd(probe_hwnd: int, profile: Profile) -> int:
|
||||
"""native_helper 实际注入 hwnd。
|
||||
|
||||
若 profile.native_hwnd_class 已设:优先同 PID 下该 class 窗(如浮层 probe、主窗注入)。
|
||||
找不到则回退 probe_hwnd,并打 warning。
|
||||
"""
|
||||
cls = (getattr(profile, "native_hwnd_class", None) or "").strip()
|
||||
if not cls:
|
||||
return int(probe_hwnd)
|
||||
try:
|
||||
pid = get_window_pid(int(probe_hwnd))
|
||||
hit = find_same_pid_hwnd_by_class(pid=pid, class_name=cls)
|
||||
except Exception as exc:
|
||||
_logger.warning(
|
||||
"resolve_native_hwnd failed profile=%s probe=%s err=%s; fallback probe",
|
||||
profile.id,
|
||||
probe_hwnd,
|
||||
exc,
|
||||
)
|
||||
return int(probe_hwnd)
|
||||
if not hit:
|
||||
_logger.warning(
|
||||
"resolve_native_hwnd miss profile=%s native_hwnd_class=%s pid=%s "
|
||||
"probe=%s; fallback probe (may crash popup UI)",
|
||||
profile.id,
|
||||
cls,
|
||||
pid,
|
||||
probe_hwnd,
|
||||
)
|
||||
return int(probe_hwnd)
|
||||
if int(hit) != int(probe_hwnd):
|
||||
_logger.info(
|
||||
"native_hwnd redirect profile=%s probe=%s -> inject=%s class=%s pid=%s",
|
||||
profile.id,
|
||||
probe_hwnd,
|
||||
hit,
|
||||
cls,
|
||||
pid,
|
||||
)
|
||||
return int(hit)
|
||||
|
||||
|
||||
def _strategy_activate(hwnd: int, profile: Profile) -> Tuple[str, str]:
|
||||
maximize = bool(getattr(profile, "activate_maximize", True))
|
||||
activate_hwnd(hwnd, maximize=maximize)
|
||||
@@ -152,6 +200,7 @@ def wake(
|
||||
"""
|
||||
require_windows()
|
||||
prof = load_profile(profile) if isinstance(profile, str) else profile
|
||||
# probe / activate 目标(如 SearchResultWindow2)
|
||||
h = find_hwnd_for_profile(prof, hwnd=hwnd)
|
||||
steps: list[WakeStepResult] = []
|
||||
|
||||
@@ -163,7 +212,11 @@ def wake(
|
||||
)
|
||||
continue
|
||||
try:
|
||||
detail, status = fn(h, prof)
|
||||
# native_helper:可重定向到同 PID 主窗注入;其余策略仍作用在 probe 窗
|
||||
target = resolve_native_hwnd(h, prof) if name == "native_helper" else h
|
||||
detail, status = fn(target, prof)
|
||||
if name == "native_helper" and int(target) != int(h):
|
||||
detail = f"inject_hwnd={target} probe_hwnd={h} | {detail}"
|
||||
steps.append(
|
||||
WakeStepResult(
|
||||
strategy=name,
|
||||
@@ -184,6 +237,7 @@ def wake(
|
||||
time.sleep(pause_s)
|
||||
if stop_when_warm:
|
||||
try:
|
||||
# 始终对 profile 目标窗(浮层)判暖,不是 inject 窗
|
||||
pr = probe(prof, hwnd=h)
|
||||
if pr.warm:
|
||||
steps.append(
|
||||
|
||||
Reference in New Issue
Block a user