Skip to content

Commit 4d6e690

Browse files
committed
Add restart method to XcodeInspector
1 parent c909e08 commit 4d6e690

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,24 @@ public final class XcodeInspector: ObservableObject {
7979
latestActiveXcode?.realtimeProjectURL ?? activeProjectRootURL
8080
}
8181

82-
public func restart() {
83-
activeXcodeObservations.forEach { $0.cancel() }
84-
activeXcodeObservations.removeAll()
85-
activeXcodeCancellable.forEach { $0.cancel() }
86-
activeXcodeCancellable.removeAll()
87-
activeXcode = nil
88-
latestActiveXcode = nil
89-
activeApplication = nil
90-
activeProjectRootURL = nil
91-
activeDocumentURL = nil
92-
activeWorkspaceURL = nil
93-
focusedWindow = nil
94-
focusedEditor = nil
95-
focusedElement = nil
96-
completionPanel = nil
97-
xcodes = []
98-
}
99-
100-
init() {
82+
public func restart(cleanUp: Bool = false) {
83+
if cleanUp {
84+
activeXcodeObservations.forEach { $0.cancel() }
85+
activeXcodeObservations.removeAll()
86+
activeXcodeCancellable.forEach { $0.cancel() }
87+
activeXcodeCancellable.removeAll()
88+
activeXcode = nil
89+
latestActiveXcode = nil
90+
activeApplication = nil
91+
activeProjectRootURL = nil
92+
activeDocumentURL = nil
93+
activeWorkspaceURL = nil
94+
focusedWindow = nil
95+
focusedEditor = nil
96+
focusedElement = nil
97+
completionPanel = nil
98+
}
99+
101100
let runningApplications = NSWorkspace.shared.runningApplications
102101
xcodes = runningApplications
103102
.filter { $0.isXcode }
@@ -107,6 +106,10 @@ public final class XcodeInspector: ObservableObject {
107106
activeApplication = activeXcode ?? runningApplications
108107
.first(where: \.isActive)
109108
.map(AppInstanceInspector.init(runningApplication:))
109+
}
110+
111+
init() {
112+
restart()
110113

111114
Task { // Did activate app
112115
if let activeXcode {

0 commit comments

Comments
 (0)