From 5d33d3a4ba3c3a9b9d06fa23f424daf1c2f697cf Mon Sep 17 00:00:00 2001 From: metacodes Date: Sun, 20 Mar 2022 11:21:12 +0800 Subject: [PATCH] fix: some app is active but can not get windows workaround: sometimes some apps are launched and are actived but OS returns the windows.count == 0. we wait for a moment. For example: Bear.app. At this scenario, AXUIElementCopyAttributeValue(self, kAXWindowsAttribute, &value) returns success but AXUIElementCopyAttributeValue(self, kAXPositionAttribute, &value) and AXUIElementCopyAttributeValue(self, kAXSizeAttribute, &value) return attributeUnsupported. After we wait for a moment, all things run well. --- src/logic/Application.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/logic/Application.swift b/src/logic/Application.swift index 933156e6b..8327297a0 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -117,6 +117,11 @@ class Application: NSObject { if group == nil && !self.wasLaunchedBeforeAltTab && CGSSpaceGetType(cgsMainConnectionId, Spaces.currentSpaceId) == .fullscreen { throw AxError.runtimeError } + // workaround: sometimes some apps are launched and are actived but OS returns the windows.count == 0. we wait for a moment + // for example: Bear.app + if group == nil && !self.wasLaunchedBeforeAltTab && self.runningApplication.isActive { + throw AxError.runtimeError + } } } }