From c1f3a30031ddd4d9e38066d6a91cca7116f6e4cc Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 27 Nov 2025 11:03:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Tweak=20AppUpdater=20with?= =?UTF-8?q?=20MainActor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/App/AppUpdater.swift | 136 +++++++++++++---------------- 1 file changed, 63 insertions(+), 73 deletions(-) diff --git a/phpmon/Domain/App/AppUpdater.swift b/phpmon/Domain/App/AppUpdater.swift index d9793e4c..15da55d5 100644 --- a/phpmon/Domain/App/AppUpdater.swift +++ b/phpmon/Domain/App/AppUpdater.swift @@ -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