Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix _get_window_by_id

Dillon DuPont3f574bb96602
diff --git a/libs/python/computer-server/computer_server/handlers/generic.py b/libs/python/computer-server/computer_server/handlers/generic.py
index d771a6b662..0ece5cdb41 100644
--- a/libs/python/computer-server/computer_server/handlers/generic.py
+++ b/libs/python/computer-server/computer_server/handlers/generic.py
@@ -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