From dec041e09030c4488e93ae867548597e3edc6c3d Mon Sep 17 00:00:00 2001 From: ant013 Date: Thu, 12 Oct 2023 16:53:12 +0600 Subject: [PATCH] Fix check version app --- .../Core/Managers/AppVersionManager.swift | 31 +++++++--------- .../UnstoppableWallet/Models/AppVersion.swift | 37 +++++++------------ .../Modules/Main/MainViewController.swift | 1 - .../Modules/Main/MainViewModel.swift | 4 -- .../Modules/Main/ReleaseNotesService.swift | 6 +-- 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AppVersionManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AppVersionManager.swift index b90263d4e7..1f37fd9c1b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AppVersionManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AppVersionManager.swift @@ -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 } - } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AppVersion.swift b/UnstoppableWallet/UnstoppableWallet/Models/AppVersion.swift index 24d1f363d0..1be834bf41 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AppVersion.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AppVersion.swift @@ -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 { @@ -56,3 +38,12 @@ extension AppVersion: CustomStringConvertible { } } + +extension AppVersion { + enum Change { + case none + case version + case build + case downgrade + } +} \ No newline at end of file diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewController.swift index 05b9bbd603..2e9fad859b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewController.swift @@ -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() }) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewModel.swift index 89c771689c..b1a44d68c4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/MainViewModel.swift @@ -120,10 +120,6 @@ extension MainViewModel { service.setMainShownOnce() } - func onReleaseNotesShown() { - releaseNotesService.updateStoredVersion() - } - func onSuccessJailbreakAlert() { jailbreakService.setAlertShown() } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/ReleaseNotesService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/ReleaseNotesService.swift index 72f4d2578d..02d35513d5 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/ReleaseNotesService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/ReleaseNotesService.swift @@ -12,7 +12,7 @@ class ReleaseNotesService { } var releaseNotesUrl: URL? { - let version = appVersionManager.newVersion?.releaseNotesVersion + let version = appVersionManager.checkVersionUpdate()?.releaseNotesVersion if let version { return URL(string: Self.releaseUrl + version) @@ -20,10 +20,6 @@ class ReleaseNotesService { return nil } - func updateStoredVersion() { - appVersionManager.updateStoredVersion() - } - var lastVersionUrl: URL? { URL(string: Self.releaseUrl + appVersionManager.currentVersion.releaseNotesVersion) }