mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: support linkable AboutView properties
This allows us to enrich the build's commit property as a GitHub link. This change also displays the property values using a monospaced font, which I think looks a little nicer (especially the commit SHA).
This commit is contained in:
@ -3,7 +3,7 @@ import SwiftUI
|
||||
struct AboutView: View {
|
||||
@Environment(\.openURL) var openURL
|
||||
|
||||
private let githubLink = URL(string: "https://github.com/ghostty-org/ghostty")
|
||||
private let githubURL = URL(string: "https://github.com/ghostty-org/ghostty")
|
||||
|
||||
/// Read the commit from the bundle.
|
||||
private var build: String? { Bundle.main.infoDictionary?["CFBundleVersion"] as? String }
|
||||
@ -11,25 +11,6 @@ struct AboutView: View {
|
||||
private var version: String? { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String }
|
||||
private var copyright: String? { Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String }
|
||||
|
||||
private var properties: [KeyValue<String>] {
|
||||
let list: [KeyValue<String?>] = [
|
||||
.init(key: "Version", value: version),
|
||||
.init(key: "Build", value: build),
|
||||
.init(key: "Commit", value: commit == "" ? nil : commit)
|
||||
]
|
||||
|
||||
return list.compactMap {
|
||||
guard let value = $0.value else { return nil }
|
||||
return .init(key: $0.key, value: value)
|
||||
}
|
||||
}
|
||||
|
||||
private struct KeyValue<Value: Equatable>: Identifiable {
|
||||
var id = UUID()
|
||||
public let key: LocalizedStringResource
|
||||
public let value: Value
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
// This creates a background style similar to the Apple "About My Mac" Window
|
||||
private struct VisualEffectBackground: NSViewRepresentable {
|
||||
@ -80,27 +61,23 @@ struct AboutView: View {
|
||||
.opacity(0.8)
|
||||
}
|
||||
.textSelection(.enabled)
|
||||
|
||||
VStack(spacing: 2) {
|
||||
ForEach(properties) { item in
|
||||
HStack(spacing: 4) {
|
||||
Text(item.key)
|
||||
.frame(width: 126, alignment: .trailing)
|
||||
.padding(.trailing, 2)
|
||||
Text(item.value)
|
||||
.frame(width: 125, alignment: .leading)
|
||||
.padding(.leading, 2)
|
||||
.tint(.secondary)
|
||||
.opacity(0.8)
|
||||
}
|
||||
.font(.callout)
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity)
|
||||
if let version {
|
||||
propertyRow("Version", text: version)
|
||||
}
|
||||
if let build {
|
||||
propertyRow("Build", text: build)
|
||||
}
|
||||
if let commit, commit != "",
|
||||
let url = githubURL?.appendingPathComponent("/commits/\(commit)") {
|
||||
propertyRow("Commit", text: commit, url: url)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
HStack(spacing: 8) {
|
||||
if let url = githubLink {
|
||||
if let url = githubURL {
|
||||
Button("GitHub") {
|
||||
openURL(url)
|
||||
}
|
||||
@ -127,6 +104,33 @@ struct AboutView: View {
|
||||
.background(VisualEffectBackground(material: .underWindowBackground).ignoresSafeArea())
|
||||
#endif
|
||||
}
|
||||
|
||||
private func propertyRow(_ label: LocalizedStringResource, text: String, url: URL? = nil) -> some View {
|
||||
HStack(spacing: 4) {
|
||||
Text(label)
|
||||
.frame(width: 126, alignment: .trailing)
|
||||
.padding(.trailing, 2)
|
||||
if let url {
|
||||
Link(destination: url) {
|
||||
propertyText(text)
|
||||
}
|
||||
} else {
|
||||
propertyText(text)
|
||||
}
|
||||
}
|
||||
.font(.callout)
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
private func propertyText(_ text: String) -> some View {
|
||||
Text(text)
|
||||
.frame(width: 125, alignment: .leading)
|
||||
.padding(.leading, 2)
|
||||
.tint(.secondary)
|
||||
.opacity(0.8)
|
||||
.monospaced()
|
||||
}
|
||||
}
|
||||
|
||||
struct AboutView_Previews: PreviewProvider {
|
||||
|
Reference in New Issue
Block a user