mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-27 22:40: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,96 +47,86 @@ 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
|
||||
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.direct".localized
|
||||
)
|
||||
.withPrimary(
|
||||
text: "updater.alerts.buttons.install".localized,
|
||||
action: { vc in
|
||||
self.cleanupCaskroom()
|
||||
self.prepareForDownload()
|
||||
vc.close(with: .OK)
|
||||
}
|
||||
)
|
||||
.withSecondary(
|
||||
text: "updater.alerts.buttons.release_notes".localized,
|
||||
action: { _ in
|
||||
NSWorkspace.shared.open({
|
||||
if App.identifier.contains(".eap") {
|
||||
return Constants.Urls.EarlyAccessChangelog
|
||||
} else {
|
||||
let urlSegments = self.caskFile.url.split(separator: "/")
|
||||
let tag = urlSegments[urlSegments.count - 2] // ../download/{tag}/{file.zip}
|
||||
return Constants.Urls.GitHubReleases.appendingPathComponent("/tag/\(tag)")
|
||||
}
|
||||
}())
|
||||
}
|
||||
)
|
||||
.withTertiary(text: "updater.alerts.buttons.dismiss".localized, action: { vc 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("brew upgrade phpmon")
|
||||
: "updater.installation_source.direct".localized
|
||||
)
|
||||
.withPrimary(
|
||||
text: "updater.alerts.buttons.install".localized,
|
||||
action: { vc in
|
||||
self.cleanupCaskroom()
|
||||
self.prepareForDownload()
|
||||
vc.close(with: .OK)
|
||||
})
|
||||
.show()
|
||||
}
|
||||
}
|
||||
)
|
||||
.withSecondary(
|
||||
text: "updater.alerts.buttons.release_notes".localized,
|
||||
action: { _ in
|
||||
NSWorkspace.shared.open({
|
||||
if App.identifier.contains(".eap") {
|
||||
return Constants.Urls.EarlyAccessChangelog
|
||||
} else {
|
||||
let urlSegments = self.caskFile.url.split(separator: "/")
|
||||
let tag = urlSegments[urlSegments.count - 2] // ../download/{tag}/{file.zip}
|
||||
return Constants.Urls.GitHubReleases.appendingPathComponent("/tag/\(tag)")
|
||||
}
|
||||
}())
|
||||
}
|
||||
)
|
||||
.withTertiary(text: "updater.alerts.buttons.dismiss".localized, action: { vc in
|
||||
vc.close(with: .OK)
|
||||
})
|
||||
.show()
|
||||
}
|
||||
|
||||
public func presentNoNewerVersionAvailableAlert() {
|
||||
Task { @MainActor in
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.is_latest_version.title".localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
||||
description: ""
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
@MainActor public func presentNoNewerVersionAvailableAlert() {
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.is_latest_version.title".localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle".localized(App.shortVersion),
|
||||
description: ""
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
|
||||
public func presentCouldNotRetrieveUpdate() {
|
||||
Task { @MainActor in
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.cannot_check_for_update.title".localized,
|
||||
subtitle: "updater.alerts.cannot_check_for_update.subtitle".localized,
|
||||
description: "updater.alerts.cannot_check_for_update.description".localized(
|
||||
App.version
|
||||
)
|
||||
@MainActor public func presentCouldNotRetrieveUpdate() {
|
||||
NVAlert().withInformation(
|
||||
title: "updater.alerts.cannot_check_for_update.title".localized,
|
||||
subtitle: "updater.alerts.cannot_check_for_update.subtitle".localized,
|
||||
description: "updater.alerts.cannot_check_for_update.description".localized(
|
||||
App.version
|
||||
)
|
||||
.withTertiary(
|
||||
text: "updater.alerts.buttons.releases_on_github".localized,
|
||||
action: { _ in
|
||||
NSWorkspace.shared.open(Constants.Urls.GitHubReleases)
|
||||
}
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
)
|
||||
.withTertiary(
|
||||
text: "updater.alerts.buttons.releases_on_github".localized,
|
||||
action: { _ in
|
||||
NSWorkspace.shared.open(Constants.Urls.GitHubReleases)
|
||||
}
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
|
||||
// MARK: - Preparing for Self-Updater
|
||||
|
||||
Reference in New Issue
Block a user