Fail hands accessibility reads fast when an app stops answering
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user