fix: better subscription retry logic
This commit is contained in:
1 parent
e03cac426b
commit
3a80caba99
1 file changed
+14
-7
@@ -54,14 +54,12 @@ extension AXUIElement {
|
||||
if let runningApplication = runningApplication, Applications.appsInSubscriptionRetryLoop.first(where: { $0 == String(runningApplication.processIdentifier) + String(notification) }) == nil { return }
|
||||
if let wid = wid, Windows.windowsInSubscriptionRetryLoop.first(where: { $0 == String(wid) + String(notification) }) == nil { return }
|
||||
let result = AXObserverAddNotification(axObserver, self, notification as CFString, pointer)
|
||||
if result == .success || result == .notificationUnsupported || result == .notificationAlreadyRegistered {
|
||||
if result == .success || result == .notificationAlreadyRegistered {
|
||||
callback?()
|
||||
if let runningApplication = runningApplication {
|
||||
Application.stopSubscriptionRetries(notification, runningApplication)
|
||||
}
|
||||
if let wid = wid {
|
||||
Window.stopSubscriptionRetries(notification, wid)
|
||||
}
|
||||
stopRetries(runningApplication, wid, notification)
|
||||
return
|
||||
} else if result == .notificationUnsupported || result == .notImplemented {
|
||||
stopRetries(runningApplication, wid, notification)
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(10), execute: { [weak self] in
|
||||
@@ -70,6 +68,15 @@ extension AXUIElement {
|
||||
})
|
||||
}
|
||||
|
||||
func stopRetries(_ runningApplication: NSRunningApplication?, _ wid: CGWindowID?, _ notification: String) {
|
||||
if let runningApplication = runningApplication {
|
||||
Application.stopSubscriptionRetries(notification, runningApplication)
|
||||
}
|
||||
if let wid = wid {
|
||||
Window.stopSubscriptionRetries(notification, wid)
|
||||
}
|
||||
}
|
||||
|
||||
private func attribute<T>(_ key: String, _ type: T.Type) -> T? {
|
||||
var value: AnyObject?
|
||||
let result = AXUIElementCopyAttributeValue(self, key as CFString, &value)
|
||||
|
||||
Reference in new issue
Block a user