Fail hands accessibility reads fast when an app stops answering

This commit is contained in:
Ian Gulliver
2026-10-18 08:43:52 -07:00
parent 1020d7eb15
commit 7f62df19d2
4 changed files with 36 additions and 30 deletions
+4 -4
View File
@@ -65,9 +65,9 @@ func post(_ e: CGEvent?) {
e?.post(tap: .cghidEventTap)
}
func isFront(_ info: WindowInfo) -> Bool {
func isFront(_ info: WindowInfo) throws -> Bool {
guard NSWorkspace.shared.frontmostApplication?.processIdentifier == info.pid,
let focused = attr(appElement(info.pid), kAXFocusedWindowAttribute)
let focused = try attr(appElement(info.pid), kAXFocusedWindowAttribute)
else {
return false
}
@@ -77,14 +77,14 @@ func isFront(_ info: WindowInfo) -> Bool {
func focusWindow(_ id: Int, _ w: AXUIElement) async throws -> WindowInfo {
let info = try window(id)
if isFront(info) {
if try isFront(info) {
return info
}
NSRunningApplication(processIdentifier: info.pid)?.activate()
AXUIElementPerformAction(w, kAXRaiseAction as CFString)
await pause(150)
let now = try window(id)
if !isFront(now) {
if try !isFront(now) {
throw ToolError("could not bring window \(id) to the front (\(NSWorkspace.shared.frontmostApplication?.localizedName ?? "nothing") is frontmost), so no input was sent")
}
return now