mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-01 17:20:09 +02: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,96 +47,86 @@ 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"
|
NVAlert().withInformation(
|
||||||
|
title: "updater.alerts.newer_version_available.title"
|
||||||
Task { @MainActor in
|
.localized(latestVersionOnline.humanReadable),
|
||||||
NVAlert().withInformation(
|
subtitle: "updater.alerts.newer_version_available.subtitle"
|
||||||
title: "updater.alerts.newer_version_available.title"
|
.localized,
|
||||||
.localized(latestVersionOnline.humanReadable),
|
description: BrewDiagnostics.shared.customCaskInstalled
|
||||||
subtitle: "updater.alerts.newer_version_available.subtitle"
|
? "updater.installation_source.brew".localized("brew upgrade phpmon")
|
||||||
.localized,
|
: "updater.installation_source.direct".localized
|
||||||
description: BrewDiagnostics.shared.customCaskInstalled
|
)
|
||||||
? "updater.installation_source.brew".localized(command)
|
.withPrimary(
|
||||||
: "updater.installation_source.direct".localized
|
text: "updater.alerts.buttons.install".localized,
|
||||||
)
|
action: { vc in
|
||||||
.withPrimary(
|
self.cleanupCaskroom()
|
||||||
text: "updater.alerts.buttons.install".localized,
|
self.prepareForDownload()
|
||||||
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
|
|
||||||
vc.close(with: .OK)
|
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() {
|
@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),
|
description: ""
|
||||||
description: ""
|
)
|
||||||
)
|
.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,
|
description: "updater.alerts.cannot_check_for_update.description".localized(
|
||||||
description: "updater.alerts.cannot_check_for_update.description".localized(
|
App.version
|
||||||
App.version
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.withTertiary(
|
)
|
||||||
text: "updater.alerts.buttons.releases_on_github".localized,
|
.withTertiary(
|
||||||
action: { _ in
|
text: "updater.alerts.buttons.releases_on_github".localized,
|
||||||
NSWorkspace.shared.open(Constants.Urls.GitHubReleases)
|
action: { _ in
|
||||||
}
|
NSWorkspace.shared.open(Constants.Urls.GitHubReleases)
|
||||||
)
|
}
|
||||||
.withPrimary(text: "generic.ok".localized)
|
)
|
||||||
.show()
|
.withPrimary(text: "generic.ok".localized)
|
||||||
}
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Preparing for Self-Updater
|
// MARK: - Preparing for Self-Updater
|
||||||
|
|||||||
Reference in New Issue
Block a user