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
|
||||
|
||||
guard let caskFile = try? await CaskFile.fromUrl(App.shared.container, caskUrl) else {
|
||||
presentCouldNotRetrieveUpdateIfInteractive()
|
||||
await presentCouldNotRetrieveUpdateIfInteractive()
|
||||
return .networkError
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class AppUpdater {
|
||||
|
||||
guard let onlineVersion = AppVersion.from(caskFile.version) else {
|
||||
Log.err("The version string from the CaskFile could not be read.")
|
||||
presentCouldNotRetrieveUpdateIfInteractive()
|
||||
await presentCouldNotRetrieveUpdateIfInteractive()
|
||||
return .parseError
|
||||
}
|
||||
|
||||
@@ -47,35 +47,30 @@ class AppUpdater {
|
||||
Log.info("The latest version read from '\(caskUrl.lastPathComponent)' is: v\(onlineVersion.computerReadable).")
|
||||
|
||||
if latestVersionOnline > currentVersion {
|
||||
presentNewerVersionAvailableAlert()
|
||||
await presentNewerVersionAvailableAlert()
|
||||
} else if interactive {
|
||||
presentNoNewerVersionAvailableAlert()
|
||||
await presentNoNewerVersionAvailableAlert()
|
||||
}
|
||||
|
||||
return .success
|
||||
}
|
||||
|
||||
private func presentCouldNotRetrieveUpdateIfInteractive() {
|
||||
@MainActor private func presentCouldNotRetrieveUpdateIfInteractive() {
|
||||
if interactive {
|
||||
return presentCouldNotRetrieveUpdate()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Alerts
|
||||
|
||||
public func presentNewerVersionAvailableAlert() {
|
||||
let command = "brew upgrade phpmon"
|
||||
|
||||
Task { @MainActor in
|
||||
@MainActor public func presentNewerVersionAvailableAlert() {
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.newer_version_available.title"
|
||||
.localized(latestVersionOnline.humanReadable),
|
||||
subtitle: "updater.alerts.newer_version_available.subtitle"
|
||||
.localized,
|
||||
description: BrewDiagnostics.shared.customCaskInstalled
|
||||
? "updater.installation_source.brew".localized(command)
|
||||
? "updater.installation_source.brew".localized("brew upgrade phpmon")
|
||||
: "updater.installation_source.direct".localized
|
||||
)
|
||||
.withPrimary(
|
||||
@@ -105,10 +100,8 @@ class AppUpdater {
|
||||
})
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
public func presentNoNewerVersionAvailableAlert() {
|
||||
Task { @MainActor in
|
||||
@MainActor public func presentNoNewerVersionAvailableAlert() {
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.is_latest_version.title".localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
||||
@@ -117,10 +110,8 @@ class AppUpdater {
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
public func presentCouldNotRetrieveUpdate() {
|
||||
Task { @MainActor in
|
||||
@MainActor public func presentCouldNotRetrieveUpdate() {
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.cannot_check_for_update.title".localized,
|
||||
subtitle: "updater.alerts.cannot_check_for_update.subtitle".localized,
|
||||
@@ -137,7 +128,6 @@ class AppUpdater {
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Preparing for Self-Updater
|
||||
|
||||
|
||||
Reference in New Issue
Block a user