@@ -160,14 +160,16 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
160160 uiElement: window,
161161 axNotifications: axNotifications
162162 )
163- focusedWindow = window
164163
165164 focusedWindowObservations. forEach { $0. cancel ( ) }
166165 focusedWindowObservations. removeAll ( )
167166
168- documentURL = window. documentURL
169- workspaceURL = window. workspaceURL
170- projectRootURL = window. projectRootURL
167+ Task { @MainActor in
168+ focusedWindow = window
169+ documentURL = window. documentURL
170+ workspaceURL = window. workspaceURL
171+ projectRootURL = window. projectRootURL
172+ }
171173
172174 window. $documentURL
173175 . filter { $0 != . init( fileURLWithPath: " / " ) }
@@ -190,10 +192,14 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
190192
191193 } else {
192194 let window = XcodeWindowInspector ( uiElement: window)
193- focusedWindow = window
195+ Task { @MainActor in
196+ focusedWindow = window
197+ }
194198 }
195199 } else {
196- focusedWindow = nil
200+ Task { @MainActor in
201+ focusedWindow = nil
202+ }
197203 }
198204 }
199205
@@ -226,7 +232,8 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
226232 for await notification in axNotificationStream {
227233 guard let self else { return }
228234 try Task . checkCancellation ( )
229-
235+ await Task . yield ( )
236+
230237 guard let event = AXNotificationKind ( rawValue: notification. name) else {
231238 continue
232239 }
@@ -258,19 +265,23 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
258265 switch event {
259266 case . created:
260267 if isCompletionPanel ( ) {
261- completionPanel = notification. element
262- self . axNotifications. send ( . init(
263- kind: . xcodeCompletionPanelChanged,
264- element: notification. element
265- ) )
268+ await MainActor . run {
269+ self . completionPanel = notification. element
270+ self . axNotifications. send ( . init(
271+ kind: . xcodeCompletionPanelChanged,
272+ element: notification. element
273+ ) )
274+ }
266275 }
267276 case . uiElementDestroyed:
268277 if isCompletionPanel ( ) {
269- completionPanel = nil
270- self . axNotifications. send ( . init(
271- kind: . xcodeCompletionPanelChanged,
272- element: notification. element
273- ) )
278+ await MainActor . run {
279+ self . completionPanel = nil
280+ self . axNotifications. send ( . init(
281+ kind: . xcodeCompletionPanelChanged,
282+ element: notification. element
283+ ) )
284+ }
274285 }
275286 default : continue
276287 }
@@ -319,7 +330,10 @@ extension XcodeAppInstanceInspector {
319330
320331 func updateWorkspaceInfo( ) {
321332 let workspaceInfoInVisibleSpace = Self . fetchVisibleWorkspaces ( runningApplication)
322- workspaces = Self . updateWorkspace ( workspaces, with: workspaceInfoInVisibleSpace)
333+ let workspaces = Self . updateWorkspace ( workspaces, with: workspaceInfoInVisibleSpace)
334+ Task { @MainActor in
335+ self . workspaces = workspaces
336+ }
323337 }
324338
325339 /// Use the project path as the workspace identifier.
0 commit comments