mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-28 06:50:08 +01:00
♻️ Tweak AppUpdater with MainActor
This commit is contained in:
@@ -29,7 +29,7 @@ class AppUpdater {
|
|||||||
let caskUrl = Constants.Urls.UpdateCheckEndpoint
|
let caskUrl = Constants.Urls.UpdateCheckEndpoint
|
||||||
|
|
||||||
guard let caskFile = try? await CaskFile.fromUrl(App.shared.container, caskUrl) else {
|
guard let caskFile = try? await CaskFile.fromUrl(App.shared.container, caskUrl) else {
|
||||||
presentCouldNotRetrieveUpdateIfInteractive()
|
await presentCouldNotRetrieveUpdateIfInteractive()
|
||||||
return .networkError
|
return .networkError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class AppUpdater {
|
|||||||
|
|
||||||
guard let onlineVersion = AppVersion.from(caskFile.version) else {
|
guard let onlineVersion = AppVersion.from(caskFile.version) else {
|
||||||
Log.err("The version string from the CaskFile could not be read.")
|
Log.err("The version string from the CaskFile could not be read.")
|
||||||
presentCouldNotRetrieveUpdateIfInteractive()
|
await presentCouldNotRetrieveUpdateIfInteractive()
|
||||||
return .parseError
|
return .parseError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,35 +47,30 @@ class AppUpdater {
|
|||||||
Log.info("The latest version read from '\(caskUrl.lastPathComponent)' is: v\(onlineVersion.computerReadable).")
|
Log.info("The latest version read from '\(caskUrl.lastPathComponent)' is: v\(onlineVersion.computerReadable).")
|
||||||
|
|
||||||
if latestVersionOnline > currentVersion {
|
if latestVersionOnline > currentVersion {
|
||||||
presentNewerVersionAvailableAlert()
|
await presentNewerVersionAvailableAlert()
|
||||||
} else if interactive {
|
} else if interactive {
|
||||||
presentNoNewerVersionAvailableAlert()
|
await presentNoNewerVersionAvailableAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
return .success
|
return .success
|
||||||
}
|
}
|
||||||
|
|
||||||
private func presentCouldNotRetrieveUpdateIfInteractive() {
|
@MainActor private func presentCouldNotRetrieveUpdateIfInteractive() {
|
||||||
if interactive {
|
if interactive {
|
||||||
return presentCouldNotRetrieveUpdate()
|
return presentCouldNotRetrieveUpdate()
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Alerts
|
// MARK: - Alerts
|
||||||
|
|
||||||
public func presentNewerVersionAvailableAlert() {
|
@MainActor public func presentNewerVersionAvailableAlert() {
|
||||||
let command = "brew upgrade phpmon"
|
|
||||||
|
|
||||||
Task { @MainActor in
|
|
||||||
NVAlert().withInformation(
|
NVAlert().withInformation(
|
||||||
title: "updater.alerts.newer_version_available.title"
|
title: "updater.alerts.newer_version_available.title"
|
||||||
.localized(latestVersionOnline.humanReadable),
|
.localized(latestVersionOnline.humanReadable),
|
||||||
subtitle: "updater.alerts.newer_version_available.subtitle"
|
subtitle: "updater.alerts.newer_version_available.subtitle"
|
||||||
.localized,
|
.localized,
|
||||||
description: BrewDiagnostics.shared.customCaskInstalled
|
description: BrewDiagnostics.shared.customCaskInstalled
|
||||||
? "updater.installation_source.brew".localized(command)
|
? "updater.installation_source.brew".localized("brew upgrade phpmon")
|
||||||
: "updater.installation_source.direct".localized
|
: "updater.installation_source.direct".localized
|
||||||
)
|
)
|
||||||
.withPrimary(
|
.withPrimary(
|
||||||
@@ -105,10 +100,8 @@ class AppUpdater {
|
|||||||
})
|
})
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func presentNoNewerVersionAvailableAlert() {
|
@MainActor public func presentNoNewerVersionAvailableAlert() {
|
||||||
Task { @MainActor in
|
|
||||||
NVAlert().withInformation(
|
NVAlert().withInformation(
|
||||||
title: "updater.alerts.is_latest_version.title".localized,
|
title: "updater.alerts.is_latest_version.title".localized,
|
||||||
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
||||||
@@ -117,10 +110,8 @@ class AppUpdater {
|
|||||||
.withPrimary(text: "generic.ok".localized)
|
.withPrimary(text: "generic.ok".localized)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func presentCouldNotRetrieveUpdate() {
|
@MainActor public func presentCouldNotRetrieveUpdate() {
|
||||||
Task { @MainActor in
|
|
||||||
NVAlert().withInformation(
|
NVAlert().withInformation(
|
||||||
title: "updater.alerts.cannot_check_for_update.title".localized,
|
title: "updater.alerts.cannot_check_for_update.title".localized,
|
||||||
subtitle: "updater.alerts.cannot_check_for_update.subtitle".localized,
|
subtitle: "updater.alerts.cannot_check_for_update.subtitle".localized,
|
||||||
@@ -137,7 +128,6 @@ class AppUpdater {
|
|||||||
.withPrimary(text: "generic.ok".localized)
|
.withPrimary(text: "generic.ok".localized)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Preparing for Self-Updater
|
// MARK: - Preparing for Self-Updater
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user