@@ -12,6 +12,12 @@ public extension Notification.Name {
1212 static let accessibilityAPIMalfunctioning = Notification . Name ( " accessibilityAPIMalfunctioning " )
1313}
1414
15+ @globalActor
16+ public enum XcodeInspectorActor : GlobalActor {
17+ public actor Actor { }
18+ public static let shared = Actor ( )
19+ }
20+
1521public final class XcodeInspector : ObservableObject {
1622 public static let shared = XcodeInspector ( )
1723
@@ -145,19 +151,19 @@ public final class XcodeInspector: ObservableObject {
145151 if let existed = xcodes. first ( where: {
146152 $0. processIdentifier == app. processIdentifier && !$0. isTerminated
147153 } ) {
148- await MainActor . run {
149- self . setActiveXcode ( existed)
154+ Task { @ XcodeInspectorActor in
155+ await self . setActiveXcode ( existed)
150156 }
151157 } else {
152158 let new = XcodeAppInstanceInspector ( runningApplication: app)
153- await MainActor . run {
159+ Task { @ XcodeInspectorActor in
154160 self . xcodes. append ( new)
155- self . setActiveXcode ( new)
161+ await self . setActiveXcode ( new)
156162 }
157163 }
158164 } else {
159165 let appInspector = AppInstanceInspector ( runningApplication: app)
160- await MainActor . run {
166+ Task { @ XcodeInspectorActor in
161167 self . previousActiveApplication = self . activeApplication
162168 self . activeApplication = appInspector
163169 }
@@ -176,7 +182,7 @@ public final class XcodeInspector: ObservableObject {
176182 else { continue }
177183 if app. isXcode {
178184 let processIdentifier = app. processIdentifier
179- await MainActor . run {
185+ Task { @ XcodeInspectorActor in
180186 self . xcodes. removeAll {
181187 $0. processIdentifier == processIdentifier || $0. isTerminated
182188 }
@@ -207,7 +213,7 @@ public final class XcodeInspector: ObservableObject {
207213 }
208214
209215 try await Task . sleep ( nanoseconds: 10_000_000_000 )
210- await MainActor . run {
216+ Task { @ XcodeInspectorActor in
211217 self . checkForAccessibilityMalfunction ( " Timer " )
212218 }
213219 }
@@ -231,15 +237,15 @@ public final class XcodeInspector: ObservableObject {
231237 }
232238
233239 public func reactivateObservationsToXcode( ) {
234- Task { @MainActor in
240+ Task { @XcodeInspectorActor in
235241 if let activeXcode {
236242 setActiveXcode ( activeXcode)
237243 activeXcode. observeAXNotifications ( )
238244 }
239245 }
240246 }
241247
242- @MainActor
248+ @XcodeInspectorActor
243249 private func setActiveXcode( _ xcode: XcodeAppInstanceInspector ) {
244250 previousActiveApplication = activeApplication
245251 activeApplication = xcode
@@ -258,7 +264,7 @@ public final class XcodeInspector: ObservableObject {
258264 activeWorkspaceURL = xcode. workspaceURL
259265 focusedWindow = xcode. focusedWindow
260266
261- let setFocusedElement = { @MainActor [ weak self] in
267+ let setFocusedElement = { @XcodeInspectorActor [ weak self] in
262268 guard let self else { return }
263269 focusedElement = xcode. appElement. focusedElement
264270 if let editorElement = focusedElement, editorElement. isSourceEditor {
@@ -279,7 +285,7 @@ public final class XcodeInspector: ObservableObject {
279285 }
280286
281287 setFocusedElement ( )
282- let focusedElementChanged = Task { @MainActor in
288+ let focusedElementChanged = Task { @XcodeInspectorActor in
283289 for await notification in xcode. axNotifications {
284290 if notification. kind == . focusedUIElementChanged {
285291 try Task . checkCancellation ( )
@@ -293,7 +299,7 @@ public final class XcodeInspector: ObservableObject {
293299 if UserDefaults . shared
294300 . value ( for: \. restartXcodeInspectorIfAccessibilityAPIIsMalfunctioning)
295301 {
296- let malfunctionCheck = Task { @MainActor [ weak self] in
302+ let malfunctionCheck = Task { @XcodeInspectorActor [ weak self] in
297303 if #available( macOS 13 . 0 , * ) {
298304 let notifications = xcode. axNotifications. filter {
299305 $0. kind == . uiElementDestroyed
@@ -334,7 +340,7 @@ public final class XcodeInspector: ObservableObject {
334340
335341 private var lastRecoveryFromAccessibilityMalfunctioningTimeStamp = Date ( )
336342
337- @MainActor
343+ @XcodeInspectorActor
338344 private func checkForAccessibilityMalfunction( _ source: String ) {
339345 guard Date ( ) . timeIntervalSince ( lastRecoveryFromAccessibilityMalfunctioningTimeStamp) > 5
340346 else { return }
@@ -356,7 +362,7 @@ public final class XcodeInspector: ObservableObject {
356362 }
357363 }
358364
359- @MainActor
365+ @XcodeInspectorActor
360366 private func recoverFromAccessibilityMalfunctioning( _ source: String ? ) {
361367 let message = """
362368 Accessibility API malfunction detected: \
0 commit comments