From b307251f81409663bf5013905eed63c04a55019c Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 6 May 2023 21:03:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Health=20check=20in=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Common/PHP/PhpInstallation.swift | 4 +++- .../Integrations/Homebrew/BrewFormula.swift | 17 ++++++++++++++--- .../SwiftUI/PhpManager/PhpFormulaeView.swift | 9 ++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/phpmon/Common/PHP/PhpInstallation.swift b/phpmon/Common/PHP/PhpInstallation.swift index 0eb0126..5658747 100644 --- a/phpmon/Common/PHP/PhpInstallation.swift +++ b/phpmon/Common/PHP/PhpInstallation.swift @@ -45,7 +45,9 @@ class PhpInstallation { withStandardError: true ).trimmingCharacters(in: .whitespacesAndNewlines) - if testCommand.contains("Library not loaded") { + // If the "dyld: Library not loaded" issue pops up, we have an unhealthy PHP installation + // and we will need to reinstall this version of PHP via Homebrew. + if testCommand.contains("Library not loaded") && testCommand.contains("dyld") { self.isHealthy = false Log.err("The PHP installation of \(self.versionNumber.short) is not healthy!") } diff --git a/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift b/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift index 1ea7e32..c50483c 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewFormula.swift @@ -39,8 +39,19 @@ struct BrewFormula { return "\(Paths.optPath)/\(resolved)/bin" } - public func isHealthy() -> Bool { - return true - // #error("This must check if the PHP version works") + var shortVersion: String? { + guard let version = self.installedVersion else { + return nil + } + + return VersionNumber.make(from: version)?.short ?? nil + } + + public func isHealthy() -> Bool? { + guard let shortVersion = self.shortVersion else { + return nil + } + + return PhpEnv.shared.cachedPhpInstallations[shortVersion]?.isHealthy ?? nil } } diff --git a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift index 1cd18e2..ac13164 100644 --- a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift +++ b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift @@ -133,7 +133,14 @@ struct PhpFormulaeView: View { .padding(.horizontal, 5) VStack(alignment: .leading) { Text(formula.displayName).bold() - // Text(formula.homebrewFolder) + + if formula.isHealthy() == nil { + Text("Unknown health") + } else { + Text(formula.isHealthy()! ? "Health OK" : "Broken!") + } + + Text(formula.homebrewFolder) if formula.isInstalled && formula.hasUpgrade { Text("\(formula.installedVersion!) installed, \(formula.upgradeVersion!) available.")