@@ -12,6 +12,10 @@ public final class AXNotificationStream: AsyncSequence {
1212 private var continuation : Continuation
1313 private let stream : Stream
1414
15+ private let file : StaticString
16+ private let line : UInt
17+ private let function : StaticString
18+
1519 public func makeAsyncIterator( ) -> Stream . AsyncIterator {
1620 stream. makeAsyncIterator ( )
1721 }
@@ -23,16 +27,32 @@ public final class AXNotificationStream: AsyncSequence {
2327 public convenience init (
2428 app: NSRunningApplication ,
2529 element: AXUIElement ? = nil ,
26- notificationNames: String ...
30+ notificationNames: String ... ,
31+ file: StaticString = #file,
32+ line: UInt = #line,
33+ function: StaticString = #function
2734 ) {
28- self . init ( app: app, element: element, notificationNames: notificationNames)
35+ self . init (
36+ app: app,
37+ element: element,
38+ notificationNames: notificationNames,
39+ file: file,
40+ line: line,
41+ function: function
42+ )
2943 }
3044
3145 public init (
3246 app: NSRunningApplication ,
3347 element: AXUIElement ? = nil ,
34- notificationNames: [ String ]
48+ notificationNames: [ String ] ,
49+ file: StaticString = #file,
50+ line: UInt = #line,
51+ function: StaticString = #function
3552 ) {
53+ self . file = file
54+ self . line = line
55+ self . function = function
3656 var cont : Continuation !
3757 stream = Stream { continuation in
3858 cont = continuation
@@ -74,7 +94,7 @@ public final class AXNotificationStream: AsyncSequence {
7494 )
7595 }
7696
77- Task { [ weak self] in
97+ Task { @ MainActor [ weak self] in
7898 CFRunLoopAddSource (
7999 CFRunLoopGetMain ( ) ,
80100 AXObserverGetRunLoopSource ( observer) ,
@@ -101,10 +121,12 @@ public final class AXNotificationStream: AsyncSequence {
101121 Logger . service. error ( " AXObserver: Action unsupported: \( name) " )
102122 pendingRegistrationNames. remove ( name)
103123 case . apiDisabled:
104- Logger . service. error ( " AXObserver: Accessibility API disabled, will try again later " )
124+ Logger . service
125+ . error ( " AXObserver: Accessibility API disabled, will try again later " )
105126 retry -= 1
106127 case . invalidUIElement:
107- Logger . service. error ( " AXObserver: Invalid UI element " )
128+ Logger . service
129+ . error ( " AXObserver: Invalid UI element, notification name \( name) " )
108130 pendingRegistrationNames. remove ( name)
109131 case . invalidUIElementObserver:
110132 Logger . service. error ( " AXObserver: Invalid UI element observer " )
@@ -116,10 +138,13 @@ public final class AXNotificationStream: AsyncSequence {
116138 Logger . service. error ( " AXObserver: Notification unsupported: \( name) " )
117139 pendingRegistrationNames. remove ( name)
118140 case . notificationAlreadyRegistered:
141+ Logger . service. info ( " AXObserver: Notification already registered: \( name) " )
119142 pendingRegistrationNames. remove ( name)
120143 default :
121144 Logger . service
122- . error ( " AXObserver: Unrecognized error \( e) when registering \( name) , will try again later " )
145+ . error (
146+ " AXObserver: Unrecognized error \( e) when registering \( name) , will try again later "
147+ )
123148 }
124149 }
125150 try await Task . sleep ( nanoseconds: 1_500_000_000 )
0 commit comments