Skip to content

Commit d4c811c

Browse files
committed
Add realtimeActiveProjectURL
1 parent 48acf04 commit d4c811c

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

Pro

Submodule Pro updated from d02bbce to 0034a4e

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public final class XcodeInspector: ObservableObject {
7070
public var realtimeActiveWorkspaceURL: URL {
7171
latestActiveXcode?.realtimeWorkspaceURL ?? activeWorkspaceURL
7272
}
73+
74+
public var realtimeActiveProjectURL: URL {
75+
latestActiveXcode?.realtimeProjectURL ?? activeWorkspaceURL
76+
}
7377

7478
init() {
7579
let runningApplications = NSWorkspace.shared.runningApplications
@@ -231,26 +235,35 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
231235

232236
@Published public private(set) var completionPanel: AXUIElement?
233237

234-
public var realtimeDocumentURL: URL {
238+
public var realtimeDocumentURL: URL? {
235239
guard let window = appElement.focusedWindow,
236240
window.identifier == "Xcode.WorkspaceWindow"
237241
else {
238-
return URL(fileURLWithPath: "/")
242+
return nil
239243
}
240244

241245
return WorkspaceXcodeWindowInspector.extractDocumentURL(windowElement: window)
242-
?? URL(fileURLWithPath: "/")
243246
}
244247

245-
public var realtimeWorkspaceURL: URL {
248+
public var realtimeWorkspaceURL: URL? {
246249
guard let window = appElement.focusedWindow,
247250
window.identifier == "Xcode.WorkspaceWindow"
248251
else {
249-
return URL(fileURLWithPath: "/")
252+
return nil
250253
}
251254

252255
return WorkspaceXcodeWindowInspector.extractWorkspaceURL(windowElement: window)
253-
?? URL(fileURLWithPath: "/")
256+
}
257+
258+
public var realtimeProjectURL: URL? {
259+
guard let window = appElement.focusedWindow else { return URL(fileURLWithPath: "/") }
260+
let workspaceURL = realtimeWorkspaceURL
261+
let documentURL = realtimeDocumentURL
262+
return WorkspaceXcodeWindowInspector.extractProjectURL(
263+
windowElement: window,
264+
workspaceURL: workspaceURL,
265+
documentURL: documentURL
266+
)
254267
}
255268

256269
var _version: String?

0 commit comments

Comments
 (0)