Skip to content

Commit df7ad31

Browse files
committed
Bring back some main actors
1 parent 060e08c commit df7ad31

4 files changed

Lines changed: 45 additions & 22 deletions

File tree

Pro

Submodule Pro updated from 3d7a24e to b53b442

Tool/Sources/XcodeInspector/Apps/XcodeAppInstanceInspector.swift

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

Tool/Sources/XcodeInspector/SourceEditor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class SourceEditor {
7676
group.addTask { [weak self] in
7777
for await notification in editorNotifications {
7878
try Task.checkCancellation()
79+
await Task.yield()
7980
guard let self else { return }
8081
if let kind: AXNotificationKind = {
8182
switch notification.name {
@@ -102,6 +103,7 @@ public class SourceEditor {
102103
group.addTask { [weak self] in
103104
for await notification in scrollViewNotifications {
104105
try Task.checkCancellation()
106+
await Task.yield()
105107
guard let self else { return }
106108
self.axNotifications.send(.init(
107109
kind: .scrollPositionChanged,

Tool/Sources/XcodeInspector/XcodeWindowInspector.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public final class WorkspaceXcodeWindowInspector: XcodeWindowInspector {
5555
guard notification.kind == .focusedUIElementChanged else { continue }
5656
guard let self else { return }
5757
try Task.checkCancellation()
58+
await Task.yield()
5859
await self.updateURLs()
5960
}
6061
}
@@ -66,18 +67,24 @@ public final class WorkspaceXcodeWindowInspector: XcodeWindowInspector {
6667
func updateURLs() {
6768
let documentURL = Self.extractDocumentURL(windowElement: uiElement)
6869
if let documentURL {
69-
self.documentURL = documentURL
70+
Task { @MainActor in
71+
self.documentURL = documentURL
72+
}
7073
}
7174
let workspaceURL = Self.extractWorkspaceURL(windowElement: uiElement)
7275
if let workspaceURL {
73-
self.workspaceURL = workspaceURL
76+
Task { @MainActor in
77+
self.workspaceURL = workspaceURL
78+
}
7479
}
7580
let projectURL = Self.extractProjectURL(
7681
workspaceURL: workspaceURL,
7782
documentURL: documentURL
7883
)
7984
if let projectURL {
80-
projectRootURL = projectURL
85+
Task { @MainActor in
86+
self.projectRootURL = projectURL
87+
}
8188
}
8289
}
8390

0 commit comments

Comments
 (0)