mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
- Make spinner view opaque to hide incorrect info when refreshing PHP installations - Resolve each PHP installation to a Homebrew version - Fix an issue where certain PHP upgrades don't show up In this build, resolving PHP upgrades happens based on the formula name. This avoids issues where available PHP version upgrades would *not* be detected correctly (based on the installed version).
67 lines
2.1 KiB
Swift
67 lines
2.1 KiB
Swift
//
|
|
// BrewFormulaeHandler.swift
|
|
// PHP Monitor
|
|
//
|
|
// Created by Nico Verbruggen on 21/03/2023.
|
|
// Copyright © 2023 Nico Verbruggen. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
protocol HandlesBrewPhpFormulae {
|
|
func loadPhpVersions(loadOutdated: Bool) async -> [BrewPhpFormula]
|
|
func refreshPhpVersions(loadOutdated: Bool) async
|
|
}
|
|
|
|
extension HandlesBrewPhpFormulae {
|
|
public func refreshPhpVersions(loadOutdated: Bool) async {
|
|
let items = await loadPhpVersions(loadOutdated: loadOutdated)
|
|
Task { @MainActor in
|
|
await PhpEnvironments.shared.determinePhpAlias()
|
|
Brew.shared.formulae.phpVersions = items
|
|
}
|
|
}
|
|
}
|
|
|
|
class BrewPhpFormulaeHandler: HandlesBrewPhpFormulae {
|
|
public func loadPhpVersions(loadOutdated: Bool) async -> [BrewPhpFormula] {
|
|
var outdated: [OutdatedFormula]?
|
|
|
|
if loadOutdated {
|
|
let command = """
|
|
\(Paths.brew) update >/dev/null && \
|
|
\(Paths.brew) outdated --json --formulae
|
|
"""
|
|
|
|
let rawJsonText = await Shell.pipe(command).out
|
|
.data(using: .utf8)!
|
|
outdated = try? JSONDecoder().decode(
|
|
OutdatedFormulae.self,
|
|
from: rawJsonText
|
|
).formulae.filter({ formula in
|
|
formula.name.starts(with: "php")
|
|
})
|
|
}
|
|
|
|
return Brew.phpVersionFormulae.map { (version, formula) in
|
|
var fullVersion: String?
|
|
var upgradeVersion: String?
|
|
|
|
if let install = PhpEnvironments.shared.cachedPhpInstallations[version] {
|
|
fullVersion = install.versionNumber.text
|
|
upgradeVersion = outdated?.first(where: { formula in
|
|
return formula.name == install.formulaName
|
|
})?.current_version
|
|
}
|
|
|
|
return BrewPhpFormula(
|
|
name: formula,
|
|
displayName: "PHP \(version)",
|
|
installedVersion: fullVersion,
|
|
upgradeVersion: upgradeVersion,
|
|
prerelease: Constants.ExperimentalPhpVersions.contains(version)
|
|
)
|
|
}.sorted { $0.displayName > $1.displayName }
|
|
}
|
|
}
|