@@ -88,9 +88,11 @@ public final class XcodeInspector: ObservableObject {
8888 . first ( where: \. isActive)
8989 . map ( AppInstanceInspector . init ( runningApplication: ) )
9090
91- Task { @MainActor in // Did activate app
91+ #warning("Test Me")
92+
93+ Task { // Did activate app
9294 if let activeXcode {
93- setActiveXcode ( activeXcode)
95+ await setActiveXcode ( activeXcode)
9496 }
9597
9698 let sequence = NSWorkspace . shared. notificationCenter
@@ -101,23 +103,30 @@ public final class XcodeInspector: ObservableObject {
101103 . userInfo ? [ NSWorkspace . applicationUserInfoKey] as? NSRunningApplication
102104 else { continue }
103105 if app. isXcode {
104- if let existed = xcodes. first (
105- where: { $0. runningApplication. processIdentifier == app. processIdentifier }
106- ) {
107- setActiveXcode ( existed)
106+ if let existed = xcodes. first ( where: {
107+ $0. runningApplication. processIdentifier == app. processIdentifier
108+ } ) {
109+ await MainActor . run {
110+ setActiveXcode ( existed)
111+ }
108112 } else {
109113 let new = XcodeAppInstanceInspector ( runningApplication: app)
110- xcodes. append ( new)
111- setActiveXcode ( new)
114+ await MainActor . run {
115+ xcodes. append ( new)
116+ setActiveXcode ( new)
117+ }
112118 }
113119 } else {
114- previousActiveApplication = activeApplication
115- activeApplication = AppInstanceInspector ( runningApplication: app)
120+ let appInspector = AppInstanceInspector ( runningApplication: app)
121+ await MainActor . run {
122+ previousActiveApplication = activeApplication
123+ activeApplication = appInspector
124+ }
116125 }
117126 }
118127 }
119128
120- Task { @ MainActor in // Did terminate app
129+ Task { // Did terminate app
121130 let sequence = NSWorkspace . shared. notificationCenter
122131 . notifications ( named: NSWorkspace . didTerminateApplicationNotification)
123132 for await notification in sequence {
@@ -126,25 +135,26 @@ public final class XcodeInspector: ObservableObject {
126135 . userInfo ? [ NSWorkspace . applicationUserInfoKey] as? NSRunningApplication
127136 else { continue }
128137 if app. isXcode {
129- xcodes. removeAll {
130- $0. runningApplication. processIdentifier == app. processIdentifier
131- }
132- if latestActiveXcode? . runningApplication. processIdentifier
133- == app. processIdentifier
134- {
135- latestActiveXcode = nil
136- }
137-
138- if let activeXcode = xcodes. first ( where: \. isActive) {
139- setActiveXcode ( activeXcode)
138+ let processIdentifier = app. processIdentifier
139+ await MainActor . run {
140+ xcodes. removeAll {
141+ $0. runningApplication. processIdentifier == processIdentifier
142+ }
143+ if latestActiveXcode? . runningApplication
144+ . processIdentifier == processIdentifier
145+ {
146+ latestActiveXcode = nil
147+ }
148+
149+ if let activeXcode = xcodes. first ( where: \. isActive) {
150+ setActiveXcode ( activeXcode)
151+ }
140152 }
141153 }
142154 }
143155 }
144156 }
145157
146- #warning("TODO: Double check before releasing 0.27.0")
147-
148158 @MainActor
149159 func setActiveXcode( _ xcode: XcodeAppInstanceInspector ) {
150160 previousActiveApplication = activeApplication
0 commit comments