mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
👌 Changes to updater
This commit is contained in:
@ -23,6 +23,15 @@ class AppVersionTest: XCTestCase {
|
||||
XCTAssertEqual(nil, version?.suffix)
|
||||
}
|
||||
|
||||
func testCanParseCaskVersionString() {
|
||||
let version = AppVersion.from("1.0.0_600")
|
||||
|
||||
XCTAssertNotNil(version)
|
||||
XCTAssertEqual("1.0.0", version?.version)
|
||||
XCTAssertEqual("600", version?.build)
|
||||
XCTAssertEqual(nil, version?.suffix)
|
||||
}
|
||||
|
||||
func testCanParseDevVersionStringWithoutBuildNumber() {
|
||||
let version = AppVersion.from("1.0.0-dev")
|
||||
|
||||
|
@ -51,7 +51,7 @@ class AppUpdateChecker {
|
||||
|
||||
let versionString = retrieveVersionFromCask(initiatedFromBackground)
|
||||
|
||||
guard let onlineVersion = VersionExtractor.from(versionString) else {
|
||||
guard let onlineVersion = AppVersion.from(versionString) else {
|
||||
Log.err("We couldn't check for updates!")
|
||||
|
||||
// Only notify about connection issues if the request to check for updates was explicit
|
||||
@ -62,10 +62,7 @@ class AppUpdateChecker {
|
||||
return
|
||||
}
|
||||
|
||||
guard let currentVersion = VersionExtractor.from(App.shortVersion) else {
|
||||
Log.err("We couldn't parse the current version number!")
|
||||
return
|
||||
}
|
||||
let currentVersion = AppVersion.fromCurrentVersion()
|
||||
|
||||
handleVersionComparison(
|
||||
currentVersion,
|
||||
@ -75,11 +72,11 @@ class AppUpdateChecker {
|
||||
}
|
||||
|
||||
private static func handleVersionComparison(
|
||||
_ currentVersion: String,
|
||||
_ onlineVersion: String,
|
||||
_ currentVersion: AppVersion,
|
||||
_ onlineVersion: AppVersion,
|
||||
_ background: Bool
|
||||
) {
|
||||
switch onlineVersion.versionCompare(currentVersion) {
|
||||
switch onlineVersion.comparable.versionCompare(currentVersion.comparable) {
|
||||
case .orderedAscending:
|
||||
Log.info("You are running a newer version of PHP Monitor.")
|
||||
if !background { notifyVersionDoesNotNeedUpgrade() }
|
||||
@ -95,10 +92,8 @@ class AppUpdateChecker {
|
||||
private static func notifyVersionDoesNotNeedUpgrade() {
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert().withInformation(
|
||||
title: "updater.alerts.is_latest_version.title\(isDev ? "_dev" : "")"
|
||||
.localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle\(isDev ? "_dev" : "")"
|
||||
.localized(App.shortVersion),
|
||||
title: "updater.alerts.is_latest_version.title".localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
||||
description: ""
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
@ -106,13 +101,13 @@ class AppUpdateChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private static func notifyAboutNewerVersion(version: String) {
|
||||
private static func notifyAboutNewerVersion(version: AppVersion) {
|
||||
let devSuffix = isDev ? "-dev" : ""
|
||||
let command = isDev ? "brew upgrade phpmon" : "brew upgrade phpmon-dev"
|
||||
let command = isDev ? "brew upgrade phpmon-dev" : "brew upgrade phpmon"
|
||||
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert().withInformation(
|
||||
title: "updater.alerts.newer_version_available.title".localized(version),
|
||||
title: "updater.alerts.newer_version_available.title".localized(version.humanReadable),
|
||||
subtitle: "updater.alerts.newer_version_available.subtitle".localized,
|
||||
description: HomebrewDiagnostics.customCaskInstalled
|
||||
? "updater.installation_source.brew".localized(command)
|
||||
@ -123,7 +118,7 @@ class AppUpdateChecker {
|
||||
action: { vc in
|
||||
vc.close(with: .OK)
|
||||
NSWorkspace.shared.open(
|
||||
Constants.Urls.GitHubReleases.appendingPathComponent("/tag/v\(version)\(devSuffix)")
|
||||
Constants.Urls.GitHubReleases.appendingPathComponent("/tag/v\(version.version)\(devSuffix)")
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -69,8 +69,12 @@ class AppVersion {
|
||||
)
|
||||
}
|
||||
|
||||
var humanReadable: String {
|
||||
return "\(version) (\(build ?? "0"))"
|
||||
}
|
||||
|
||||
var comparable: String {
|
||||
return "\(version).\(build)"
|
||||
return "\(version).\(build ?? "0")"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ You can do this by running `composer global update` in your terminal. After that
|
||||
|
||||
// CHECK FOR UPDATES
|
||||
|
||||
"updater.alerts.newer_version_available.title" = "A newer version of PHP Monitor (v%@) is now available!";
|
||||
"updater.alerts.newer_version_available.title" = "PHP Monitor v%@ is now available!";
|
||||
"updater.alerts.newer_version_available.subtitle" = "Keeping PHP Monitor up-to-date is highly recommended, since newer versions usually fix bugs and include fixes to support the latest versions of Valet and PHP.";
|
||||
"updater.alerts.newer_version_available.description" = "PHP Monitor is supposed to be updated via Homebrew, so there is no built-in updater. This check is only meant to inform you of the existence of a new version, you do not need to upgrade.";
|
||||
"updater.installation_source.brew" = "You appear to have installed PHP Monitor via Homebrew (or have at least tapped the required Caskfile) so it is recommended that you upgrade via the terminal by running `%@`.";
|
||||
@ -390,9 +390,6 @@ You can do this by running `composer global update` in your terminal. After that
|
||||
"updater.alerts.is_latest_version.title" = "PHP Monitor is up-to-date!";
|
||||
"updater.alerts.is_latest_version.subtitle" = "The currently installed version (v%@) is up-to-date.\nThere is no newer version available.";
|
||||
|
||||
"updater.alerts.is_latest_version.title_dev" = "PHP Monitor DEV is (probably) up-to-date!";
|
||||
"updater.alerts.is_latest_version.subtitle_dev" = "You appear to be running a development build. While no major newer version seems to be available, a newer dev build for the same version may be available, and it is recommended that you check if that is the case. Thanks for testing!";
|
||||
|
||||
"updater.alerts.cannot_check_for_update.title" = "PHP Monitor could not determine if a newer version is available.";
|
||||
"updater.alerts.cannot_check_for_update.subtitle" = "You might not be connected to the internet, are blocking traffic or GitHub is down and won't allow you to check for updates. If you keep seeing this message, you may want to manually check the releases page.";
|
||||
"updater.alerts.cannot_check_for_update.description" = "The currently installed version is: %@. You can go to the list of the latest releases (on GitHub) by clicking on the button on the left.";
|
||||
|
Reference in New Issue
Block a user