Skip to content

Commit

Permalink
Fix check version app
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Oct 12, 2023
1 parent 5f62ff1 commit dec041e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 50 deletions.
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

0 comments on commit dec041e

Please sign in to comment.