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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
import SwiftUI
import SwiftUIIntrospect
struct AboutContributor: Identifiable {
let id: UUID = UUID()
let username: String
let webURL: URL
let pictureURL: URL?
}
struct AboutContributorView: View {
@Environment(\.openURL) private var openURL
let contributor: AboutContributor
var body: some View {
HStack {
if let pictureURL = contributor.pictureURL {
AsyncImage(url: pictureURL) { phase in
if let image = phase.image {
image
.interpolation(.high)
.resizable()
.scaledToFit()
.background(.white)
.frame(width: 32, height: 32)
} else if phase.error != nil {
Color.clear
.frame(width: 32, height: 32)
} else {
Color.white
.opacity(0.2)
.frame(width: 32, height: 32)
}
}
.frame(width: 32, height: 32)
.clipShape(Circle())
}
VStack(alignment: .leading, spacing: 2) {
Text(contributor.username)
.fontWeight(.semibold)
.foregroundStyle(.white)
.lineLimit(1)
Text(contributor.webURL.absoluteString)
.lineLimit(1)
.truncationMode(.middle)
.font(.system(size: 11))
.foregroundStyle(.white.opacity(0.4))
}
}
// }
// .accessibilityAddTraits(.isLink)
// .pointerStyle(.link)
}
}
struct AboutView: View {
@Environment(\.openURL) private var openURL
@State private var contributors: [AboutContributor] = []
var body: some View {
HStack(alignment: .center, spacing: 0) {
self.brandView
self.contributorsList
.background {
Color.black.blendMode(.softLight).opacity(0.3).ignoresSafeArea()
}
}
.frame(width: 570, height: 330)
.background(
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .center, spacing: 0) {
Divider()
Spacer()
}
.frame(height: 330 + 100)
.offset(x: 250)
}
)
.task {
await loadContributors()
}
}
private var brandView: some View {
VStack(alignment: .center, spacing: 4) {
Spacer()
Image("About Hotline")
Text("Hotline")
.font(.system(size: 28))
.fontWeight(.bold)
.padding(.top, 12)
.kerning(-1.0)
.foregroundColor(.white)
let appDetails = getAppVersionAndBuild()
Button {
self.openURL(URL(string: "https://github.com/mierau/hotline/releases/tag/\(appDetails.version)beta\(appDetails.build)")!)
} label: {
Text("Version \(String(format: "%.1f", appDetails.version))b\(appDetails.build)")
.foregroundColor(.white.opacity(0.756))
.padding(.vertical, 4)
.padding(.horizontal, 12)
.background {
Capsule()
.fill(.white.opacity(0.5))
.blendMode(.softLight)
}
}
.buttonStyle(.plain)
.buttonBorderShape(.capsule)
.padding(.bottom, 16)
Spacer()
}
.frame(width: 250)
}
private var contributorsList: some View {
ScrollView(.vertical) {
VStack(alignment: .leading, spacing: 16) {
self.contributorHeaderView
ForEach(self.contributors) { contributor in
Button {
self.openURL(contributor.webURL)
} label: {
AboutContributorView(contributor: contributor)
}
.buttonStyle(.plain)
.accessibilityAddTraits(.isLink)
.pointerStyle(.link)
}
}
.frame(maxWidth: .infinity)
.padding()
}
.scrollClipDisabled()
.scrollContentBackground(.hidden)
// .introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) { v in
// v.automaticallyAdjustsContentInsets = false
// }
}
private var contributorHeaderView: some View {
VStack(alignment: .leading, spacing: 4) {
Link(destination: URL(string: "https://github.com/mierau/hotline")!) {
HStack(alignment: .center, spacing: 4) {
Text("Contributors")
.lineLimit(1)
.font(.system(size: 16))
.fontWeight(.semibold)
.foregroundStyle(.black)
.opacity(0.8)
Image(systemName: "arrow.forward.circle.fill")
.resizable()
.fontWeight(.bold)
.scaledToFit()
.frame(width: 12, height: 12)
.foregroundStyle(.black)
.opacity(0.4)
}
}
.accessibilityAddTraits(.isLink)
.pointerStyle(.link)
Text("Hotline is an open source project made possible by its contributors.")
.font(.system(size: 11))
.foregroundStyle(.black)
.opacity(0.5)
.padding(.trailing, 32)
}
.padding(.bottom, 8)
}
func loadContributors() async {
var newContributors: [AboutContributor] = []
if let url = URL(string: "https://api.github.com/repos/mierau/hotline/contributors"),
let (data, _) = try? await URLSession.shared.data(from: url) {
if let jsonContributors = try? JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
for contributor in jsonContributors {
if let username = contributor["login"] as? String,
let webURLString = contributor["html_url"] as? String,
let webURL = URL(string: webURLString) {
var pictureURL: URL? = nil
if let pictureURLString = contributor["avatar_url"] as? String {
pictureURL = URL(string: pictureURLString)
}
newContributors.append(AboutContributor(username: username, webURL: webURL, pictureURL: pictureURL))
}
}
}
}
withAnimation {
contributors = newContributors
}
}
func getAppVersionAndBuild() -> (version: Double, build: Int) {
let infoDictionary = Bundle.main.infoDictionary!
let version = Double(infoDictionary["CFBundleShortVersionString"]! as! String)!
let build = Int(infoDictionary["CFBundleVersion"]! as! String)!
return (version, build)
}
}
#Preview {
AboutView()
}
|