diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-05 22:27:17 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-05 22:27:17 +0100 |
| commit | 45829daa856b376b1ab04d415917110b71b1dec5 (patch) | |
| tree | 8e52daed6897b6f489d455736fe256cb9bd90fef /Hotline/macOS/AboutView.swift | |
| parent | 5c3ea897d062a47bc8cd6255fb8c36bad2f0733f (diff) | |
Apply formatting
Diffstat (limited to 'Hotline/macOS/AboutView.swift')
| -rw-r--r-- | Hotline/macOS/AboutView.swift | 114 |
1 files changed, 59 insertions, 55 deletions
diff --git a/Hotline/macOS/AboutView.swift b/Hotline/macOS/AboutView.swift index baafcf8..a2771b9 100644 --- a/Hotline/macOS/AboutView.swift +++ b/Hotline/macOS/AboutView.swift @@ -16,31 +16,31 @@ struct AboutContributor: Identifiable { struct AboutView: View { @Environment(\.openURL) private var openURL - + @State private var versionCheck: VersionCheckState = .needToCheck @State private var downloadURL: String = "https://github.com/mierau/hotline/releases/latest" @State private var contributors: [AboutContributor] = [] - + var body: some View { HStack(alignment: .center, spacing: 0) { VStack(alignment: .center, spacing: 0) { Spacer() - + Image("About Hotline") .padding(.top, 44) - + Text("Hotline") .font(.system(size: 28)) .fontWeight(.bold) .padding(.top, 12) .kerning(-1.0) .foregroundColor(.white) - + let appDetails = getAppVersionAndBuild() Text("Version \(String(format: "%.1f", appDetails.version))b\(appDetails.build)") .foregroundColor(.white) .opacity(0.4) - + HStack(alignment: .center) { switch versionCheck { case .needToCheck: @@ -81,12 +81,12 @@ struct AboutView: View { Spacer() } .frame(width: 250) - + Spacer() - + ScrollView(.vertical) { VStack(alignment: .leading, spacing: 16) { - + VStack(alignment: .leading, spacing: 4) { Link(destination: URL(string: "https://github.com/mierau/hotline")!) { HStack(alignment: .center, spacing: 4) { @@ -107,7 +107,7 @@ struct AboutView: View { } } .padding(.top, 24) - + Text("Hotline is an open source project made possible by its contributors.") .font(.system(size: 11)) .foregroundStyle(.black) @@ -115,7 +115,7 @@ struct AboutView: View { .padding(.trailing, 32) } .padding(.bottom, 8) - + ForEach(contributors) { contributor in Link(destination: contributor.webURL) { HStack { @@ -139,27 +139,27 @@ struct AboutView: View { } .frame(width: 32, height: 32) .clipShape(Circle()) - -// AsyncImage(url: pictureURL) { img in -// img -// .interpolation(.high) -// .resizable() -// .scaledToFit() -// .background(.white) -// } placeholder: { -// Color.white.opacity(0.2) -// .frame(width: 32, height: 32) -// } -// .frame(width: 32, height: 32) -// .clipShape(Circle()) + + // AsyncImage(url: pictureURL) { img in + // img + // .interpolation(.high) + // .resizable() + // .scaledToFit() + // .background(.white) + // } placeholder: { + // 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) @@ -189,68 +189,72 @@ struct AboutView: View { await loadContributors() } } - + 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]] { + 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) { + 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)) + newContributors.append( + AboutContributor(username: username, webURL: webURL, pictureURL: pictureURL)) } } } } - + withAnimation { contributors = newContributors } } - + func checkForUpdate() async { let appDetails = getAppVersionAndBuild() - + self.versionCheck = .checking - + do { let url = URL(string: "https://api.github.com/repos/mierau/hotline/releases/latest")! let (data, _) = try await URLSession.shared.data(from: url) let versionExpression = /^([0-9\.]+)beta([0-9]+)/ - + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], - let tagName = json["tag_name"] as? String, - let assets = json["assets"] as? [[String: Any]], - let firstAsset = assets.first, - let assetDownloadURL = firstAsset["browser_download_url"] as? String, - let versionMatches = try? versionExpression.wholeMatch(in: tagName) { + let tagName = json["tag_name"] as? String, + let assets = json["assets"] as? [[String: Any]], + let firstAsset = assets.first, + let assetDownloadURL = firstAsset["browser_download_url"] as? String, + let versionMatches = try? versionExpression.wholeMatch(in: tagName) + { if let versionNumber = Double(versionMatches.1), - let buildNumber = Int(versionMatches.2), - versionNumber > appDetails.version || buildNumber > appDetails.build { - let versionString = "\(versionMatches.1)b\(versionMatches.2)" - self.versionCheck = .updateAvailable(version: versionString) - downloadURL = assetDownloadURL - } - else { + let buildNumber = Int(versionMatches.2), + versionNumber > appDetails.version || buildNumber > appDetails.build + { + let versionString = "\(versionMatches.1)b\(versionMatches.2)" + self.versionCheck = .updateAvailable(version: versionString) + downloadURL = assetDownloadURL + } else { self.versionCheck = .upToDate } - } - else { + } else { self.versionCheck = .needToCheck } - } - catch { + } catch { self.versionCheck = .needToCheck } } - + func getAppVersionAndBuild() -> (version: Double, build: Int) { let infoDictionary = Bundle.main.infoDictionary! let version = Double(infoDictionary["CFBundleShortVersionString"]! as! String)! |