From c16377c688e75a2bc1309a1718700b50d0d8274f Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 10 May 2022 18:52:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Improved=20updater?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 4 +-- phpmon/Domain/App/AppUpdateChecker.swift | 39 +++++++++++++++++++++--- phpmon/Domain/App/AppVersion.swift | 10 +++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 29e80d0..4ef7da2 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -1515,7 +1515,7 @@ C41C1B4422B0098000E7CF16 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; @@ -1541,7 +1541,7 @@ C41C1B4522B0098000E7CF16 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; diff --git a/phpmon/Domain/App/AppUpdateChecker.swift b/phpmon/Domain/App/AppUpdateChecker.swift index 329ad4f..321c870 100644 --- a/phpmon/Domain/App/AppUpdateChecker.swift +++ b/phpmon/Domain/App/AppUpdateChecker.swift @@ -76,19 +76,50 @@ class AppUpdateChecker { _ onlineVersion: AppVersion, _ background: Bool ) { - switch onlineVersion.comparable.versionCompare(currentVersion.comparable) { + switch onlineVersion.version.versionCompare(currentVersion.version) { case .orderedAscending: - Log.info("You are running a newer version of PHP Monitor.") + Log.info("You are running a newer version of PHP Monitor " + + "(\(currentVersion.computerReadable) > \(onlineVersion.computerReadable)).") if !background { notifyVersionDoesNotNeedUpgrade() } case .orderedDescending: - Log.info("There is a newer version (\(onlineVersion)) available!") + Log.info("There is a newer version (\(onlineVersion)) available! " + + "(\(onlineVersion.computerReadable) > \(currentVersion.computerReadable))") notifyAboutNewerVersion(version: onlineVersion) case .orderedSame: - Log.info("The installed version (\(currentVersion)) matches the latest release (\(onlineVersion)).") + // Check if the build number differs + if currentVersion.build != nil + && onlineVersion.build != nil + && buildDiffers(currentVersion, onlineVersion, background) { + return + } + + // If the build number does not differ... it's the same release + Log.info("The installed version (\(currentVersion.computerReadable)) matches the latest release " + + "(\(onlineVersion.computerReadable)).") if !background { notifyVersionDoesNotNeedUpgrade() } } } + private static func buildDiffers( + _ currentVersion: AppVersion, + _ onlineVersion: AppVersion, + _ background: Bool + ) -> Bool { + if Int(onlineVersion.build!)! > Int(currentVersion.build!)! { + Log.info("There is a newer build of PHP Monitor available! " + + "(\(onlineVersion.computerReadable) > \(currentVersion.computerReadable))") + notifyAboutNewerVersion(version: onlineVersion) + return true + } else if Int(onlineVersion.build!)! < Int(currentVersion.build!)! { + Log.info("You are running a newer build of PHP Monitor " + + "(\(currentVersion.computerReadable) > \(onlineVersion.computerReadable)).") + if !background { notifyVersionDoesNotNeedUpgrade() } + return true + } + + return false + } + private static func notifyVersionDoesNotNeedUpgrade() { DispatchQueue.main.async { BetterAlert().withInformation( diff --git a/phpmon/Domain/App/AppVersion.swift b/phpmon/Domain/App/AppVersion.swift index a9630db..0f05c03 100644 --- a/phpmon/Domain/App/AppVersion.swift +++ b/phpmon/Domain/App/AppVersion.swift @@ -64,17 +64,17 @@ class AppVersion { public static func fromCurrentVersion() -> AppVersion { return AppVersion( - version: App.shortVersion, + version: VersionExtractor.from(App.shortVersion)!, build: App.bundleVersion ) } - var humanReadable: String { - return "\(version) (\(build ?? "0"))" + var computerReadable: String { + return "\(version)_\(build ?? "???")" } - var comparable: String { - return "\(version).\(build ?? "0")" + var humanReadable: String { + return "\(version) (\(build ?? "???"))" } }