fix _get_window_by_id

This commit is contained in:
Dillon DuPont
2025-10-25 00:55:12 -07:00
parent 0f2187b62f
commit 3f574bb966

View File

@@ -117,12 +117,23 @@ class GenericWindowHandler(BaseWindowHandler):
except Exception as e:
return {"success": False, "error": str(e)}
def _get_window_by_id(self, window_id: int | str):
def _get_window_by_id(self, window_id: int | str) -> Optional[Any]:
if pwc is None:
raise RuntimeError("pywinctl not available")
# Find by native handle among Window objects; getAllWindowsDict keys are titles
try:
windows = pwc.getAllWindowsDict()
return windows.get(window_id) or windows.get(int(window_id))
for w in pwc.getAllWindows():
try:
handle = (
w.getHandle() if hasattr(w, "getHandle") else getattr(w, "handle", None)
)
if handle is None:
continue
if str(handle) == str(window_id):
return w
except Exception:
continue
return None
except Exception:
return None