From 48bb782e33093960633051ca27e90748b31f9a7a Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 22 Nov 2024 17:42:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20WIP:=20Changes=20related=20to=20?= =?UTF-8?q?unavailable=20formulae?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Homebrew/BrewPhpFormula.swift | 5 ++-- .../UI/PhpVersionManagerView.swift | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift index 2236a33..50f9c99 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift @@ -47,14 +47,15 @@ struct BrewPhpFormula: Equatable { var hasUpgrade: Bool { return upgradeVersion != nil } - + var hasFormulaFile: Bool { guard let version = shortVersion else { return false } - + return FileSystem.fileExists( "\(Paths.tapPath)/shivammathur/homebrew-php/Formula/php@\(version).rb" + .replacingOccurrences(of: "php@" + PhpEnvironments.brewPhpAlias, with: "php") ) } diff --git a/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift b/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift index 23b4256..e639589 100644 --- a/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift +++ b/phpmon/Modules/PHP Version Manager/UI/PhpVersionManagerView.swift @@ -269,16 +269,7 @@ struct PhpVersionManagerView: View { .font(.system(size: 11)) .foregroundColor(.gray) } else if !formula.hasFormulaFile { - HStack(spacing: 5) { - Text("phpman.version.unavailable".localizedForSwiftUI) - .font(.system(size: 11)) - .foregroundColor(.gray) - HelpButton(action: { - // Show an alert that displays information about the missing formula - // and what can be done to fix this particular issue. - // Running `brew tap shivammathur/php` generally works, I think. - }) - } + unavailableFormula() } else { Text("phpman.version.available_for_installation".localizedForSwiftUI) .font(.system(size: 11)) @@ -294,6 +285,19 @@ struct PhpVersionManagerView: View { .frame(maxWidth: .infinity, alignment: .leading) } + private func unavailableFormula() -> some View { + HStack(spacing: 5) { + Text("phpman.version.unavailable".localizedForSwiftUI) + .font(.system(size: 11)) + .foregroundColor(.gray) + HelpButton(action: { + // Show an alert that displays information about the missing formula + // and what can be done to fix this particular issue. + // Running `brew tap shivammathur/php` generally works, I think. + }) + } + } + private func formulaIcon(for formula: BrewPhpFormula) -> some View { Image(systemName: formula.icon) .resizable()