(app_bundle, max_depth, output_screenshot_dir=None, global_vis_index=None)
| 100 | |
| 101 | |
| 102 | def process_app(app_bundle, max_depth, output_screenshot_dir=None, global_vis_index=None): |
| 103 | store_screen_scaling_factor() |
| 104 | workspace = AppKit.NSWorkspace.sharedWorkspace() |
| 105 | app = apps.application_for_bundle(app_bundle, workspace) |
| 106 | if app is None: |
| 107 | print(f"App {app_bundle} not running.") |
| 108 | return [], [] |
| 109 | |
| 110 | application = apps.application_for_process_id(app.processIdentifier()) |
| 111 | windows = apps.windows_for_application(application) |
| 112 | if not windows: |
| 113 | print(f"No windows found for {app_bundle}") |
| 114 | return [], [] |
| 115 | |
| 116 | cg_entries = [e for e in (global_vis_index or []) if e["pid"] == int(app.processIdentifier())] |
| 117 | |
| 118 | all_ui_elements = [] |
| 119 | screenshot_info_list = [] |
| 120 | |
| 121 | for ax_win in windows: |
| 122 | rect = get_window_rect(ax_win) |
| 123 | if not rect: |
| 124 | continue |
| 125 | x_tl, y_tl, x2_tl, y2_tl = rect |
| 126 | w_ax, h_ax = (x2_tl - x_tl), (y2_tl - y_tl) |
| 127 | |
| 128 | best = None |
| 129 | best_iou = 0.0 |
| 130 | for cg in cg_entries: |
| 131 | cx, cy, cW, cH = cg["bounds"] |
| 132 | cand = (cx, cy, cx + cW, cy + cH) |
| 133 | iou = _iou((x_tl, y_tl, x2_tl, y2_tl), cand) |
| 134 | if iou > best_iou: |
| 135 | best_iou, best = iou, cg |
| 136 | if not best: |
| 137 | continue |
| 138 | |
| 139 | vis_rects = best["visible"] |
| 140 | # skip not visible windows |
| 141 | if not vis_rects: |
| 142 | continue |
| 143 | |
| 144 | vx1 = min(r[0] for r in vis_rects) |
| 145 | vy1 = min(r[1] for r in vis_rects) |
| 146 | vx2 = max(r[0] + r[2] for r in vis_rects) |
| 147 | vy2 = max(r[1] + r[3] for r in vis_rects) |
| 148 | |
| 149 | ix1, iy1 = max(x_tl, vx1), max(y_tl, vy1) |
| 150 | ix2, iy2 = min(x2_tl, vx2), min(y2_tl, vy2) |
| 151 | if ix2 <= ix1 or iy2 <= iy1: |
| 152 | continue |
| 153 | |
| 154 | parents_visible_bbox = [ |
| 155 | int(ix1 - x_tl), |
| 156 | int(iy1 - y_tl), |
| 157 | int(ix2 - x_tl), |
| 158 | int(iy2 - y_tl), |
| 159 | ] |
no test coverage detected