Skip to content

Commit a8eefe5

Browse files
committed
Fix a thread safe issue
1 parent a6830bf commit a8eefe5

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

Core/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import AXNotificationStream
55
import Combine
66
import Foundation
77

8-
#warning("MUSTDO: - store(in:) thread safe crash")
9-
108
public final class XcodeInspector: ObservableObject {
119
public static let shared = XcodeInspector()
1210

@@ -228,22 +226,26 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
228226
uiElement: window
229227
)
230228
focusedWindow = window
231-
focusedWindowObservations.forEach { $0.cancel() }
232-
focusedWindowObservations.removeAll()
233-
234-
documentURL = window.documentURL
235-
projectURL = window.projectURL
236-
237-
window.$documentURL
238-
.filter { $0 != .init(fileURLWithPath: "/") }
239-
.sink { [weak self] url in
240-
self?.documentURL = url
241-
}.store(in: &focusedWindowObservations)
242-
window.$projectURL
243-
.filter { $0 != .init(fileURLWithPath: "/") }
244-
.sink { [weak self] url in
245-
self?.projectURL = url
246-
}.store(in: &focusedWindowObservations)
229+
230+
// should find a better solution to do this thread safe
231+
Task { @MainActor in
232+
focusedWindowObservations.forEach { $0.cancel() }
233+
focusedWindowObservations.removeAll()
234+
235+
documentURL = window.documentURL
236+
projectURL = window.projectURL
237+
238+
window.$documentURL
239+
.filter { $0 != .init(fileURLWithPath: "/") }
240+
.sink { [weak self] url in
241+
self?.documentURL = url
242+
}.store(in: &focusedWindowObservations)
243+
window.$projectURL
244+
.filter { $0 != .init(fileURLWithPath: "/") }
245+
.sink { [weak self] url in
246+
self?.projectURL = url
247+
}.store(in: &focusedWindowObservations)
248+
}
247249
} else {
248250
let window = XcodeWindowInspector(uiElement: window)
249251
focusedWindow = window

0 commit comments

Comments
 (0)