Skip to content

Commit 8076180

Browse files
committed
Fix concurrency warning
1 parent 41c95ff commit 8076180

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public actor RealtimeSuggestionController {
2626
func start() {
2727
Task { [weak self] in
2828
if let app = ActiveApplicationMonitor.shared.activeXcode {
29-
await self?.handleXcodeChanged(app)
29+
await self?.handleXcodeChanged()
3030
}
3131
var previousApp = ActiveApplicationMonitor.shared.activeXcode
3232
for await app in ActiveApplicationMonitor.shared.createStream() {
@@ -35,13 +35,14 @@ public actor RealtimeSuggestionController {
3535
defer { previousApp = app }
3636

3737
if let app = ActiveApplicationMonitor.shared.activeXcode, app != previousApp {
38-
await self.handleXcodeChanged(app)
38+
await self.handleXcodeChanged()
3939
}
4040
}
4141
}
4242
}
4343

44-
private func handleXcodeChanged(_ app: NSRunningApplication) {
44+
private func handleXcodeChanged() {
45+
guard let app = ActiveApplicationMonitor.shared.activeXcode else { return }
4546
windowChangeObservationTask?.cancel()
4647
windowChangeObservationTask = nil
4748
observeXcodeWindowChangeIfNeeded(app)
@@ -50,12 +51,13 @@ public actor RealtimeSuggestionController {
5051
private func observeXcodeWindowChangeIfNeeded(_ app: NSRunningApplication) {
5152
guard windowChangeObservationTask == nil else { return }
5253
handleFocusElementChange()
54+
55+
let notifications = AXNotificationStream(
56+
app: app,
57+
notificationNames: kAXFocusedUIElementChangedNotification,
58+
kAXMainWindowChangedNotification
59+
)
5360
windowChangeObservationTask = Task { [weak self] in
54-
let notifications = AXNotificationStream(
55-
app: app,
56-
notificationNames: kAXFocusedUIElementChangedNotification,
57-
kAXMainWindowChangedNotification
58-
)
5961
for await _ in notifications {
6062
guard let self else { return }
6163
try Task.checkCancellation()
@@ -84,6 +86,12 @@ public actor RealtimeSuggestionController {
8486
editorObservationTask?.cancel()
8587
editorObservationTask = nil
8688

89+
let notificationsFromEditor = AXNotificationStream(
90+
app: activeXcode,
91+
element: focusElement,
92+
notificationNames: kAXValueChangedNotification, kAXSelectedTextChangedNotification
93+
)
94+
8795
editorObservationTask = Task { [weak self] in
8896
let fileURL = try await Environment.fetchCurrentFileURL()
8997
if let sourceEditor = await self?.sourceEditor {
@@ -93,12 +101,6 @@ public actor RealtimeSuggestionController {
93101
)
94102
}
95103

96-
let notificationsFromEditor = AXNotificationStream(
97-
app: activeXcode,
98-
element: focusElement,
99-
notificationNames: kAXValueChangedNotification, kAXSelectedTextChangedNotification
100-
)
101-
102104
for await notification in notificationsFromEditor {
103105
guard let self else { return }
104106
try Task.checkCancellation()

0 commit comments

Comments
 (0)