Skip to content

Commit a64df41

Browse files
committed
fix: address code review findings
- Use downcast_into to avoid unnecessary retain/release per attribute - Suppress unused uses_language_correction warning on Windows - Clarify macOS vs Windows attribute matching difference in AGENTS.md
1 parent b9aa28d commit a64df41

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ Fast-path to get coordinates without image analysis.
6969
]
7070
```
7171
* **Platform behavior:**
72-
* **Both platforms:** Uses the **platform accessibility API** as the primary mechanism — searches the accessibility tree for elements whose name matches the query. This gives precise element-level coordinates (`confidence: 1.0`). Falls back to OCR automatically if accessibility finds no matches.
73-
* **macOS:** Accessibility API (primary), Vision OCR (fallback). Note: accessibility results use semantic names (e.g., "All Clear" instead of "AC", "Subtract" instead of "−"), so search by meaning rather than displayed symbol.
74-
* **Windows:** UI Automation (primary), WinRT OCR (fallback).
72+
* **Both platforms:** Uses the **platform accessibility API** as the primary mechanism — searches the accessibility tree for elements by name. This gives precise element-level coordinates (`confidence: 1.0`). Falls back to OCR automatically if accessibility finds no matches.
73+
* **macOS:** Accessibility API (primary), Vision OCR (fallback). Matches against element title, value, and description. Note: accessibility results use semantic names (e.g., "All Clear" instead of "AC", "Subtract" instead of "−"), so search by meaning rather than displayed symbol.
74+
* **Windows:** UI Automation (primary), WinRT OCR (fallback). Matches against element Name property only.
7575

7676
### 2. Input & Interaction (The "Hands")
7777

src/macos/ax.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ unsafe fn get_string_attribute(element: AXUIElementRef, attr_name: &str) -> Opti
179179
return None;
180180
}
181181

182-
// value_ref is owned (create rule) — wrap it so it gets released
183-
let cf_value = CFType::wrap_under_create_rule(value_ref);
184-
185-
// Try to downcast to CFString
186-
let cf_string = cf_value.downcast::<CFString>()?;
182+
// value_ref is owned (create rule) — wrap it so it gets released.
183+
// downcast_into consumes cf_value, avoiding an extra retain/release cycle.
184+
let cf_string = CFType::wrap_under_create_rule(value_ref).downcast_into::<CFString>()?;
187185
Some(cf_string.to_string())
188186
}
189187

src/tools/input.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ fn find_text_in_window(
497497
uses_language_correction,
498498
)?;
499499
#[cfg(target_os = "windows")]
500-
let mut matches = ocr::ocr_image(&screenshot.png_data, Some(screenshot.scale_factor))?;
500+
let mut matches = {
501+
let _ = uses_language_correction; // Windows OCR doesn't support this param
502+
ocr::ocr_image(&screenshot.png_data, Some(screenshot.scale_factor))?
503+
};
501504

502505
// Offset OCR coordinates from image-relative to screen-absolute
503506
for m in &mut matches {

0 commit comments

Comments
 (0)