Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check version app #5314

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
import Foundation
import RxSwift
import RxRelay
import RxSwift

class AppVersionManager {
private let systemInfoManager: SystemInfoManager
private let storage: AppVersionStorage

var newVersion: AppVersion? {
let currentVersion = systemInfoManager.appVersion

guard let lastVersion = storage.appVersions.last, currentVersion > lastVersion else {
return nil
}

return currentVersion
}

func updateStoredVersion() {
func checkVersionUpdate() -> AppVersion? {
let currentVersion = systemInfoManager.appVersion

// first start
guard let lastVersion = storage.appVersions.last else {
storage.save(appVersions: [currentVersion])
return
return nil
}

if lastVersion.version != currentVersion.version || lastVersion.build != currentVersion.build {
switch currentVersion.change(lastVersion) {
// show release
case .version:
storage.save(appVersions: [currentVersion])
return currentVersion
// just update db
case .build, .downgrade:
storage.save(appVersions: [currentVersion])
case .none: ()
}

return nil
}

init(systemInfoManager: SystemInfoManager, storage: AppVersionStorage) {
self.systemInfoManager = systemInfoManager
self.storage = storage
}

}

extension AppVersionManager {

var currentVersion: AppVersion {
systemInfoManager.appVersion
}

}
37 changes: 14 additions & 23 deletions UnstoppableWallet/UnstoppableWallet/Models/AppVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@ struct AppVersion: Codable {
Int(version.components(separatedBy: ".")[1]) ?? 0
}

private var patch: Int? {
Int(version.components(separatedBy: ".")[2])
func change(_ old: AppVersion) -> Change {
if version == old.version, build == old.build { return .none }
if major > old.major || (major == old.major && minor > old.minor) { return .version }
if version == old.version, build ?? "0" > old.build ?? "0" { return .build }
return .downgrade
}

}

extension AppVersion: Comparable {

public static func <(lhs: AppVersion, rhs: AppVersion) -> Bool {
if lhs.major < rhs.major {
return true
}

if lhs.major == rhs.major && lhs.minor < rhs.minor {
return true
}

return false
}

public static func ==(lhs: AppVersion, rhs: AppVersion) -> Bool {
lhs.version == rhs.version
}

}

extension AppVersion: CustomStringConvertible {
Expand All @@ -56,3 +38,12 @@ extension AppVersion: CustomStringConvertible {
}

}

extension AppVersion {
enum Change {
case none
case version
case build
case downgrade
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class MainViewController: ThemeTabBarController {
return
}

viewModel.onReleaseNotesShown()
let module = MarkdownModule.gitReleaseNotesMarkdownViewController(url: url, presented: true, closeHandler: { [weak self] in
self?.viewModel.handleNextAlert()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ extension MainViewModel {
service.setMainShownOnce()
}

func onReleaseNotesShown() {
releaseNotesService.updateStoredVersion()
}

func onSuccessJailbreakAlert() {
jailbreakService.setAlertShown()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ class ReleaseNotesService {
}

var releaseNotesUrl: URL? {
let version = appVersionManager.newVersion?.releaseNotesVersion
let version = appVersionManager.checkVersionUpdate()?.releaseNotesVersion

if let version {
return URL(string: Self.releaseUrl + version)
}
return nil
}

func updateStoredVersion() {
appVersionManager.updateStoredVersion()
}

var lastVersionUrl: URL? {
URL(string: Self.releaseUrl + appVersionManager.currentVersion.releaseNotesVersion)
}
Expand Down