Allow launching and copying the path of an installed Xcode

This commit is contained in:
Brandon Evans 2020-12-26 21:51:41 -07:00
parent adad238b2a
commit 912ac0a28e
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
2 changed files with 21 additions and 2 deletions

View file

@ -191,6 +191,18 @@ class AppState: ObservableObject {
// TODO:
}
func launch(id: Xcode.ID) {
guard let installedXcode = Current.files.installedXcodes(Path.root/"Applications").first(where: { $0.version == id }) else { return }
NSWorkspace.shared.openApplication(at: installedXcode.path.url, configuration: .init())
}
func copyPath(id: Xcode.ID) {
guard let installedXcode = Current.files.installedXcodes(Path.root/"Applications").first(where: { $0.version == id }) else { return }
NSPasteboard.general.declareTypes([.URL, .string], owner: nil)
NSPasteboard.general.writeObjects([installedXcode.path.url as NSURL])
NSPasteboard.general.setString(installedXcode.path.string, forType: .string)
}
// MARK: - Private
private func updateAllXcodes(_ xcodes: [AvailableXcode]) {

View file

@ -65,12 +65,19 @@ struct XcodeListView: View {
Button(action: { xcode.installed ? appState.xcodeBeingConfirmedForUninstallation = xcode : self.appState.install(id: xcode.id) }) {
Text(xcode.installed ? "Uninstall" : "Install")
}
Divider()
if xcode.installed {
Button(action: { self.appState.select(id: xcode.id) }) {
Text("Select")
}
Button(action: { self.appState.launch(id: xcode.id) }) {
Text("Launch")
}
Button(action: { self.appState.reveal(id: xcode.id) }) {
Text("Reveal in Finder")
}
Button(action: { self.appState.select(id: xcode.id) }) {
Text("Select")
Button(action: { self.appState.copyPath(id: xcode.id) }) {
Text("Copy Path")
}
}
}