Keep the last in-template copy on main so history can restore it; product continues in jiangchang-ui-recorder. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""Windows desktop dump via existing desktop_uia."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
import desktop_uia as uia
|
|
import target
|
|
from .base import DumpResult
|
|
|
|
|
|
class WindowsUiaDriver:
|
|
surface = target.SURFACE_WINDOWS
|
|
driver_name = "uiautomation"
|
|
|
|
def dump(
|
|
self,
|
|
*,
|
|
info: Any,
|
|
selection_meta: dict[str, Any],
|
|
max_depth: int = 16,
|
|
max_nodes: int = 8000,
|
|
warmup_mode: str = "full",
|
|
merge_same_pid_if_sparse: bool = True,
|
|
warmed_pids: Optional[set[object]] = None,
|
|
) -> DumpResult:
|
|
warmed = warmed_pids if warmed_pids is not None else set()
|
|
mode = warmup_mode
|
|
warm_key = (int(info.pid), str(info.class_name or ""))
|
|
if (warm_key in warmed or int(info.pid) in warmed) and mode == "full":
|
|
mode = "light"
|
|
merge_sparse = merge_same_pid_if_sparse
|
|
if (info.class_name or "") == "SearchResultWindow2":
|
|
merge_sparse = False
|
|
tree, index, stats, locatable = uia.dump_window_tree(
|
|
info.hwnd,
|
|
max_depth=max_depth,
|
|
max_nodes=max_nodes,
|
|
only_visible=False,
|
|
warmup_mode=mode,
|
|
merge_same_pid_if_sparse=merge_sparse,
|
|
)
|
|
return DumpResult(
|
|
surface=self.surface,
|
|
driver=self.driver_name,
|
|
window=info.to_dict(),
|
|
tree=tree,
|
|
index=index,
|
|
locatable=locatable,
|
|
stats=stats,
|
|
selection=dict(selection_meta or {}),
|
|
url="",
|
|
page_title="",
|
|
locatable_text=uia.format_locatable_text(locatable),
|
|
tree_text=uia.format_tree_text(tree),
|
|
screenshot_bytes=None,
|
|
use_hwnd_screenshot=True,
|
|
)
|