From eb566bb52338ba212c8ab7949d8ddf477bcf042e Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 31 Aug 2023 19:05:40 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20pre-release=20builds=20to?= =?UTF-8?q?=20be=20installed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Common/Core/Constants.swift | 15 ++++++++++++--- phpmon/Domain/Integrations/Homebrew/Brew.swift | 1 + .../Integrations/Homebrew/BrewFormula.swift | 17 +++++++++++++++++ .../Homebrew/BrewFormulaeHandler.swift | 3 ++- .../Data/Fake/FakeBrewFormulaeHandler.swift | 7 +++++++ .../UI/PhpVersionManagerView.swift | 16 +++++++++++++++- phpmon/en.lproj/Localizable.strings | 1 + 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/phpmon/Common/Core/Constants.swift b/phpmon/Common/Core/Constants.swift index 8fbef99..eeb9fd9 100644 --- a/phpmon/Common/Core/Constants.swift +++ b/phpmon/Common/Core/Constants.swift @@ -18,6 +18,13 @@ struct Constants { */ static let MinimumRecommendedValetVersion = "2.16.2" + /** + * The PHP versions that are considered pre-release versions. + */ + static let ExperimentalPhpVersions: Set = [ + "8.3", "8.4" + ] + /** * The PHP versions supported by this application. * Any other PHP versions are considered invalid. @@ -25,7 +32,9 @@ struct Constants { static let DetectedPhpVersions: Set = [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", - "8.0", "8.1", "8.2", "8.3" + "8.0", "8.1", "8.2", + "8.3", + "8.4" ] /** @@ -42,13 +51,13 @@ struct Constants { [ "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", - "8.3" // dev + "8.3", "8.4" // dev ], 4: // Valet v4 dropped support for v7.0 [ "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", - "8.3" // dev + "8.3", "8.4" // dev ] ] diff --git a/phpmon/Domain/Integrations/Homebrew/Brew.swift b/phpmon/Domain/Integrations/Homebrew/Brew.swift index 5d94ac8..4ea90d3 100644 --- a/phpmon/Domain/Integrations/Homebrew/Brew.swift +++ b/phpmon/Domain/Integrations/Homebrew/Brew.swift @@ -45,6 +45,7 @@ class Brew { /// Each formula for each PHP version that can be installed. public static let phpVersionFormulae = [ + "8.3": "shivammathur/php/php@8.3", "8.2": "php@8.2", "8.1": "php@8.1", "8.0": "php@8.0", diff --git a/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift b/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift index 140cae0..3291212 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift @@ -21,11 +21,28 @@ struct BrewFormula { /// The upgrade that is currently available, if it exists. let upgradeVersion: String? + /// Whether this formula is a stable version of PHP. + let prerelease: Bool + /// Whether the formula is currently installed. var isInstalled: Bool { return installedVersion != nil } + init( + name: String, + displayName: String, + installedVersion: String?, + upgradeVersion: String?, + prerelease: Bool = false + ) { + self.name = name + self.displayName = displayName + self.installedVersion = installedVersion + self.upgradeVersion = upgradeVersion + self.prerelease = prerelease + } + /// Whether the formula can be upgraded. var hasUpgrade: Bool { return upgradeVersion != nil diff --git a/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift b/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift index 9fb0cd4..83cddc8 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift @@ -56,7 +56,8 @@ class BrewFormulaeHandler: HandlesBrewFormulae { name: formula, displayName: "PHP \(version)", installedVersion: fullVersion, - upgradeVersion: upgradeVersion + upgradeVersion: upgradeVersion, + prerelease: Constants.ExperimentalPhpVersions.contains(version) ) }.sorted { $0.displayName > $1.displayName } } diff --git a/phpmon/Modules/PHP Version Manager/Data/Fake/FakeBrewFormulaeHandler.swift b/phpmon/Modules/PHP Version Manager/Data/Fake/FakeBrewFormulaeHandler.swift index 759fdd1..1565e85 100644 --- a/phpmon/Modules/PHP Version Manager/Data/Fake/FakeBrewFormulaeHandler.swift +++ b/phpmon/Modules/PHP Version Manager/Data/Fake/FakeBrewFormulaeHandler.swift @@ -11,6 +11,13 @@ import Foundation class FakeBrewFormulaeHandler: HandlesBrewFormulae { public func loadPhpVersions(loadOutdated: Bool) async -> [BrewFormula] { return [ + BrewFormula( + name: "php", + displayName: "PHP 8.3", + installedVersion: nil, + upgradeVersion: "8.3.0", + prerelease: true + ), BrewFormula( name: "php", displayName: "PHP 8.2", diff --git a/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift b/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift index 94a190a..bf0e3b6 100644 --- a/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift +++ b/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift @@ -135,7 +135,21 @@ struct PhpVersionManagerView: View { .foregroundColor(formula.iconColor) .padding(.horizontal, 5) VStack(alignment: .leading, spacing: 2) { - Text(formula.displayName).bold() + HStack { + Text(formula.displayName).bold() + + if formula.prerelease { + Text("phpman.version.prerelease".localized.uppercased()) + .font(.system(size: 9)) + .padding(.horizontal, 5) + .padding(.vertical, 1) + .background(Color.appPrimary) + .foregroundColor(Color.white) + .clipShape(Capsule()) + .fixedSize(horizontal: true, vertical: true) + .frame(maxHeight: 7) + } + } if formula.isInstalled && formula.hasUpgrade { Text("phpman.version.has_update".localized( diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index 3fedc24..5a3f415 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -108,6 +108,7 @@ "phpman.buttons.install" = "Install"; "phpman.buttons.update" = "Update"; "phpman.buttons.repair" = "Repair"; +"phpman.version.prerelease" = "Pre-release"; "phpman.title" = "PHP Version Manager"; "phpman.description" = "**PHP Version Manager** lets you install, upgrade and delete different PHP versions via Homebrew without needing to run the commands in the terminal yourself.";