File tree Expand file tree Collapse file tree
Tool/Sources/AXNotificationStream Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import AppKit
22import ApplicationServices
33import Foundation
44import Logger
5+ import Preferences
56
67public final class AXNotificationStream : AsyncSequence {
78 public typealias Stream = AsyncStream < Element >
@@ -53,6 +54,15 @@ public final class AXNotificationStream: AsyncSequence {
5354 self . file = file
5455 self . line = line
5556 self . function = function
57+
58+ let mode : CFRunLoopMode = UserDefaults . shared
59+ . value ( for: \. observeToAXNotificationWithDefaultMode) ? . defaultMode : . commonModes
60+
61+ let runLoop : CFRunLoop = UserDefaults . shared
62+ . value ( for: \. observeToAXNotificationOnAnotherThread)
63+ ? DispatchQueue . global ( qos: . userInteractive) . sync { CFRunLoopGetCurrent ( ) }
64+ : CFRunLoopGetMain ( )
65+
5666 var cont : Continuation !
5767 stream = Stream { continuation in
5868 cont = continuation
@@ -88,17 +98,17 @@ public final class AXNotificationStream: AsyncSequence {
8898 AXObserverRemoveNotification ( observer, observingElement, name as CFString )
8999 }
90100 CFRunLoopRemoveSource (
91- CFRunLoopGetMain ( ) ,
101+ runLoop ,
92102 AXObserverGetRunLoopSource ( observer) ,
93- . commonModes
103+ mode
94104 )
95105 }
96106
97107 Task { @MainActor [ weak self] in
98108 CFRunLoopAddSource (
99- CFRunLoopGetMain ( ) ,
109+ runLoop ,
100110 AXObserverGetRunLoopSource ( observer) ,
101- . commonModes
111+ mode
102112 )
103113 var pendingRegistrationNames = Set ( notificationNames)
104114 var retry = 0
You can’t perform that action at this time.
0 commit comments