From 7e5cbadc09268981c0d183f5be31faf98c71cf28 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 4 Apr 2023 20:50:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Various=20improvements=20to=20PH?= =?UTF-8?q?P=20Version=20Manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A warning has been added if you are not running Homebrew 4.0, since running older (or newer) versions of Homebrew are not officially supported. This check is only displayed once per cold app boot. - The PHP Version Manager now shows the full version number for up-to-date PHP installations (mostly important for patch version). - You must now confirm the deletion of an installed version of PHP before PHP Monitor will uninstall that version. - It is no longer possible to press the refresh button if the app is already busy checking for updated PHP versions --- PHP Monitor.xcodeproj/project.pbxproj | 12 ++-- phpmon/Common/Helpers/Alert.swift | 2 + .../Domain/Integrations/Homebrew/Brew.swift | 2 +- .../SwiftUI/PhpManager/PhpFormulaeView.swift | 64 +++++++++++++++---- phpmon/Localizable.strings | 25 +++++++- 5 files changed, 82 insertions(+), 23 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 23c398e..4bcc27f 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -3309,7 +3309,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3339,7 +3339,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3568,7 +3568,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3679,7 +3679,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3790,7 +3790,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3963,7 +3963,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1205; + CURRENT_PROJECT_VERSION = 1210; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; diff --git a/phpmon/Common/Helpers/Alert.swift b/phpmon/Common/Helpers/Alert.swift index bc6c8c1..64809e2 100644 --- a/phpmon/Common/Helpers/Alert.swift +++ b/phpmon/Common/Helpers/Alert.swift @@ -14,6 +14,7 @@ class Alert { messageText: String, informativeText: String, buttonTitle: String = "generic.ok".localized, + buttonIsDestructive: Bool = false, secondButtonTitle: String = "generic.cancel".localized, style: NSAlert.Style = .warning, onFirstButtonPressed: @escaping (() -> Void) @@ -27,6 +28,7 @@ class Alert { alert.messageText = messageText alert.informativeText = informativeText alert.addButton(withTitle: buttonTitle) + alert.buttons.first?.hasDestructiveAction = buttonIsDestructive if !secondButtonTitle.isEmpty { alert.addButton(withTitle: secondButtonTitle) } diff --git a/phpmon/Domain/Integrations/Homebrew/Brew.swift b/phpmon/Domain/Integrations/Homebrew/Brew.swift index d8e2883..285426d 100644 --- a/phpmon/Domain/Integrations/Homebrew/Brew.swift +++ b/phpmon/Domain/Integrations/Homebrew/Brew.swift @@ -30,7 +30,7 @@ class Brew { Log.info("The user has Homebrew \(version.text) installed.") if version.major < 4 { - Log.warn("Managing PHP versions is only supported with Homebrew 4 or newer!") + Log.warn("Managing PHP versions is only officially supported with Homebrew 4 or newer!") } } else { Log.warn("The Homebrew version could not be determined.") diff --git a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift index 1bb3004..12847a8 100644 --- a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift +++ b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift @@ -35,11 +35,28 @@ struct PhpFormulaeView: View { self.status = PhpFormulaeStatus( busy: true, - title: "Checking for updates!", - description: "Checking if any PHP version is outdated..." + title: "phpman.busy.title".localized, + description: "phpman.busy.description.outdated".localized ) Task { [self] in + guard let version = Brew.shared.version else { + return + } + + await delay(seconds: 1) + + if version.major != 4 { + Task { @MainActor in + self.presentErrorAlert( + title: "phpman.warnings.unsupported.title".localized, + description: "phpman.warnings.unsupported.desc".localized(version.text), + button: "generic.ok".localized, + style: .warning + ) + } + } + await PhpEnv.detectPhpVersions() await self.handler.refreshPhpVersions(loadOutdated: false) await self.handler.refreshPhpVersions(loadOutdated: true) @@ -74,8 +91,8 @@ struct PhpFormulaeView: View { Task { // Reload warnings Task { @MainActor in self.status.busy = true - self.status.title = "Checking for updates!" - self.status.description = "Checking if any PHP version is outdated..." + self.status.title = "phpman.busy.title".localized + self.status.description = "phpman.busy.description.outdated".localized } await self.handler.refreshPhpVersions(loadOutdated: true) Task { @MainActor in @@ -88,6 +105,7 @@ struct PhpFormulaeView: View { .controlSize(.large) } .focusable(false) + .disabled(self.status.busy) Text("phpman.refresh.button.description".localizedForSwiftUI) .foregroundColor(.gray) @@ -112,26 +130,26 @@ struct PhpFormulaeView: View { .font(.system(size: 11)) .foregroundColor(.gray) } else if formula.isInstalled && formula.installedVersion != nil { - Text("Latest version is currently installed.").font(.system(size: 11)) + Text("\(formula.installedVersion!) is currently installed.").font(.system(size: 11)) .foregroundColor(.gray) } else { - Text("This version can be installed.") + Text("phpman.version.available_for_installation".localizedForSwiftUI) .font(.system(size: 11)) .foregroundColor(.gray) } } .frame(maxWidth: .infinity, alignment: .leading) if formula.isInstalled { - Button("Uninstall") { - Task { await self.uninstall(formula) } + Button("phpman.buttons.uninstall".localizedForSwiftUI, role: .destructive) { + Task { await self.confirmUninstall(formula) } } } else { - Button("Install") { + Button("phpman.buttons.install".localizedForSwiftUI) { Task { await self.install(formula) } } } if formula.hasUpgrade { - Button("Update") { + Button("phpman.buttons.update".localizedForSwiftUI) { Task { await self.install(formula) } } } @@ -175,7 +193,7 @@ struct PhpFormulaeView: View { } } - public func uninstall(_ formula: BrewFormula) async { + public func confirmUninstall(_ formula: BrewFormula) async { // Disallow removal of the currently active versipn if formula.installedVersion == PhpEnv.shared.currentInstall?.version.text { self.presentErrorAlert( @@ -186,6 +204,21 @@ struct PhpFormulaeView: View { return } + Alert.confirm( + onWindow: App.shared.versionManagerWindowController!.window!, + messageText: "phpman.warnings.removal.title".localized(formula.displayName), + informativeText: "phpman.warnings.removal.desc".localized(formula.displayName), + buttonTitle: "phpman.warnings.removal.button".localized, + buttonIsDestructive: true, + secondButtonTitle: "generic.cancel".localized, + style: .warning, + onFirstButtonPressed: { + Task { await self.uninstall(formula) } + } + ) + } + + public func uninstall(_ formula: BrewFormula) async { let command = RemovePhpVersionCommand(formula: formula.name) do { @@ -230,14 +263,19 @@ struct PhpFormulaeView: View { } } - public func presentErrorAlert(title: String, description: String, button: String) { + public func presentErrorAlert( + title: String, + description: String, + button: String, + style: NSAlert.Style = .critical + ) { Alert.confirm( onWindow: App.shared.versionManagerWindowController!.window!, messageText: title, informativeText: description, buttonTitle: button, secondButtonTitle: "", - style: .critical, + style: style, onFirstButtonPressed: {} ) } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 8e9ee6a..ecf27a4 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -90,13 +90,32 @@ // PHPMAN +"phpman.busy.title" = "Checking for updates!"; +"phpman.busy.description.outdated" = "Checking if any PHP version is outdated..."; + +"phpman.version.available_for_installation" = "This version can be installed"; +"phpman.buttons.uninstall" = "Uninstall"; +"phpman.buttons.install" = "Install"; +"phpman.buttons.update" = "Update"; + "phpman.title" = "PHP Version Manager"; "phpman.description" = "**PHP Version Manager** lets you install different PHP versions via Homebrew."; -"phpman.disclaimer" = "Please note that installing or upgrading PHP versions may cause other Homebrew packages to be upgraded as well, but only if Homebrew would otherwise have broken those other packages via a shared dependency. (More in the FAQ!)"; +"phpman.disclaimer" = "Please note that installing or upgrading PHP versions may cause other Homebrew packages to be upgraded as well. For more information, please consult the FAQ."; "phpman.refresh.button" = "Search for Updates"; -"phpman.refresh.button.description" = "You can press this button to check (again) if any updates are available to installed PHP versions. When you first open this window, PHP Monitor already does this check."; +"phpman.refresh.button.description" = "You can press the refresh button to check if any updates are available to installed PHP versions."; -"phpman.failures.install.title" = "Install failed!"; +"phpman.warnings.unsupported.title" = "Your version of Homebrew may cause issues"; +"phpman.warnings.unsupported.desc" = "No functionality is disabled, but some commands may not work as expected. You are currently running Homebrew %@. + +Currently, Homebrew 4 is the only supported version for the PHP Version Manager. If you are running a newer version of Homebrew, you may wish to check if a newer version of PHP Monitor is available."; + +"phpman.warnings.removal.title" = "Are you sure you want to uninstall %@?"; +"phpman.warnings.removal.desc" = "Please note that configuration files will not be removed, so it should be easy to reinstall later if needed. + +You may be asked for your password during the uninstallation process if file permissions don't allow a simple removal."; +"phpman.warnings.removal.button" = "Uninstall"; + +"phpman.failures.install.title" = "Installation failed!"; "phpman.failures.install.desc" = "Unfortunately, the automatic installation failed. You can manually try to run this command: `%@` and find out what goes wrong. Remember to restart PHP Monitor (or press the refresh button) when this is done."; "phpman.uninstall_prevented.title" = "You cannot uninstall the currently active version of PHP via PHP Monitor.";