Skip to content

Commit

Permalink
Show latest update info
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Oct 16, 2024
1 parent 5b29d1c commit 33d5ddc
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions DuckDuckGo/Updates/ReleaseNotesTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ extension ReleaseNotesValues {
init(from updateController: UpdateController?) {
let currentVersion = "\(AppVersion().versionNumber) (\(AppVersion().buildNumber))"
let lastUpdate = UInt((updateController?.lastUpdateCheckDate ?? Date()).timeIntervalSince1970)
let latestVersion: String

guard let updateController else {
guard let updateController, let latestUpdate = updateController.latestUpdate else {
self.init(status: .loaded,
currentVersion: currentVersion,
lastUpdate: lastUpdate)
Expand All @@ -160,28 +159,31 @@ extension ReleaseNotesValues {
case .upToDate:
self.init(status: .loaded,
currentVersion: currentVersion,
lastUpdate: lastUpdate)
latestVersion: latestUpdate.versionString,
lastUpdate: lastUpdate,
releaseTitle: latestUpdate.title,
releaseNotes: latestUpdate.releaseNotes,
releaseNotesPrivacyPro: latestUpdate.releaseNotesPrivacyPro)
case .updateCycle(let progress):
if let latestUpdate = updateController.latestUpdate {
latestVersion = "\(latestUpdate.version) (\(latestUpdate.build))"
let status = hasPendingUpdate ? .updateReady : progress.toStatus
self.init(status: status,
currentVersion: currentVersion,
latestVersion: latestVersion,
lastUpdate: lastUpdate,
releaseTitle: latestUpdate.title,
releaseNotes: latestUpdate.releaseNotes,
releaseNotesPrivacyPro: latestUpdate.releaseNotesPrivacyPro,
downloadProgress: progress.toDownloadProgress)
} else {
self.init(status: .loaded,
currentVersion: currentVersion,
lastUpdate: lastUpdate)
}
let status = hasPendingUpdate ? .updateReady : progress.toStatus
self.init(status: status,
currentVersion: currentVersion,
latestVersion: latestUpdate.versionString,
lastUpdate: lastUpdate,
releaseTitle: latestUpdate.title,
releaseNotes: latestUpdate.releaseNotes,
releaseNotesPrivacyPro: latestUpdate.releaseNotesPrivacyPro,
downloadProgress: progress.toDownloadProgress)
}
}
}

private extension Update {
var versionString: String? {
"\(version) \(build)"
}
}

private extension UpdateCycleProgress {
var toStatus: ReleaseNotesValues.Status {
switch self {
Expand Down

0 comments on commit 33d5ddc

Please sign in to comment.