-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUtils.swift
More file actions
35 lines (30 loc) · 1.27 KB
/
Copy pathUtils.swift
File metadata and controls
35 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Foundation
import XcodeInspector
import AppKit
import Logger
class Utils {
public static func openFileInXcode(fileURL: URL, xcodeInstance: XcodeAppInstanceInspector) throws {
/// TODO: when xcode minimized, the activate not work.
guard xcodeInstance.activate(options: [.activateAllWindows, .activateIgnoringOtherApps]) else {
throw NSError(domain: "Failed to activate xcode instance", code: 0)
}
/// wait for a while to allow activation (especially un-minimizing) to complete
Thread.sleep(forTimeInterval: 0.3)
let configuration = NSWorkspace.OpenConfiguration()
configuration.activates = true
NSWorkspace.shared.open(
[fileURL],
withApplicationAt: xcodeInstance.runningApplication.bundleURL!,
configuration: configuration) { app, error in
if error != nil {
Logger.client.error("Failed to open file \(String(describing: error))")
}
}
}
public static func getXcode(by workspacePath: String) -> XcodeAppInstanceInspector? {
return XcodeInspector.shared.xcodes.first(
where: {
return $0.workspaceURL?.path == workspacePath
})
}
}