mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Merge pull request #2696 from jparise/macos-about-properties
macos: support linkable AboutView properties
This commit is contained in:
@ -3,7 +3,7 @@ import SwiftUI
|
|||||||
struct AboutView: View {
|
struct AboutView: View {
|
||||||
@Environment(\.openURL) var openURL
|
@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.
|
/// Read the commit from the bundle.
|
||||||
private var build: String? { Bundle.main.infoDictionary?["CFBundleVersion"] as? String }
|
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 version: String? { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String }
|
||||||
private var copyright: String? { Bundle.main.infoDictionary?["NSHumanReadableCopyright"] 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)
|
#if os(macOS)
|
||||||
// This creates a background style similar to the Apple "About My Mac" Window
|
// This creates a background style similar to the Apple "About My Mac" Window
|
||||||
private struct VisualEffectBackground: NSViewRepresentable {
|
private struct VisualEffectBackground: NSViewRepresentable {
|
||||||
@ -80,27 +61,23 @@ struct AboutView: View {
|
|||||||
.opacity(0.8)
|
.opacity(0.8)
|
||||||
}
|
}
|
||||||
.textSelection(.enabled)
|
.textSelection(.enabled)
|
||||||
|
|
||||||
VStack(spacing: 2) {
|
VStack(spacing: 2) {
|
||||||
ForEach(properties) { item in
|
if let version {
|
||||||
HStack(spacing: 4) {
|
PropertyRow(label: "Version", text: version)
|
||||||
Text(item.key)
|
}
|
||||||
.frame(width: 126, alignment: .trailing)
|
if let build {
|
||||||
.padding(.trailing, 2)
|
PropertyRow(label: "Build", text: build)
|
||||||
Text(item.value)
|
}
|
||||||
.frame(width: 125, alignment: .leading)
|
if let commit, commit != "",
|
||||||
.padding(.leading, 2)
|
let url = githubURL?.appendingPathComponent("/commits/\(commit)") {
|
||||||
.tint(.secondary)
|
PropertyRow(label: "Commit", text: commit, url: url)
|
||||||
.opacity(0.8)
|
|
||||||
}
|
|
||||||
.font(.callout)
|
|
||||||
.textSelection(.enabled)
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
|
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
if let url = githubLink {
|
if let url = githubURL {
|
||||||
Button("GitHub") {
|
Button("GitHub") {
|
||||||
openURL(url)
|
openURL(url)
|
||||||
}
|
}
|
||||||
@ -127,6 +104,45 @@ struct AboutView: View {
|
|||||||
.background(VisualEffectBackground(material: .underWindowBackground).ignoresSafeArea())
|
.background(VisualEffectBackground(material: .underWindowBackground).ignoresSafeArea())
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct PropertyRow: View {
|
||||||
|
private let label: String
|
||||||
|
private let text: String
|
||||||
|
private let url: URL?
|
||||||
|
|
||||||
|
init(label: String, text: String, url: URL? = nil) {
|
||||||
|
self.label = label
|
||||||
|
self.text = text
|
||||||
|
self.url = url
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder private var textView: some View {
|
||||||
|
Text(text)
|
||||||
|
.frame(width: 125, alignment: .leading)
|
||||||
|
.padding(.leading, 2)
|
||||||
|
.tint(.secondary)
|
||||||
|
.opacity(0.8)
|
||||||
|
.monospaced()
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(label)
|
||||||
|
.frame(width: 126, alignment: .trailing)
|
||||||
|
.padding(.trailing, 2)
|
||||||
|
if let url {
|
||||||
|
Link(destination: url) {
|
||||||
|
textView
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.font(.callout)
|
||||||
|
.textSelection(.enabled)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AboutView_Previews: PreviewProvider {
|
struct AboutView_Previews: PreviewProvider {
|
||||||
|
Reference in New Issue
Block a user