1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

✏️ New comments

This commit is contained in:
2022-01-29 14:13:38 +01:00
parent c4c19a5b47
commit 193f459be1
7 changed files with 54 additions and 16 deletions

View File

@ -8,8 +8,8 @@
import Foundation
/**
The `Paths` class is used to locate various binaries on the system,
and provides a full
The `Paths` class is used to locate various binaries on the system.
The path to the Homebrew directory and the user's name are fetched only once, at boot.
*/
public class Paths {

View File

@ -8,6 +8,15 @@
import Foundation
/**
This generic async helper is something I'd like to use in more places.
The `DispatchQueue.global` into `DispatchQueue.main.async` logic is common in the app.
I could also use try `async` support which was introduced in Swift but that would
require too much refactoring at this time to consider. I also need to read up on async
in order to properly grasp all the gotchas. Looking into that later at some point.
*/
public func runAsync(_ execute: @escaping () -> Void, completion: @escaping () -> Void = {})
{
DispatchQueue.global(qos: .userInitiated).async {

View File

@ -65,6 +65,9 @@ class MenuBarImageGenerator {
return targetImage
}
/**
The same as before, but also attempts to add an icon to the left.
*/
public static func textToImageWithIcon(text: String) -> NSImage {
let textImage = self.textToImage(text: text)
let iconImage = NSImage(named: "StatusBarPHP")!

View File

@ -10,6 +10,9 @@ import Foundation
class VersionExtractor {
/**
This attempts to extract the version number from the command line output of Valet.
*/
public static func from(_ string: String) -> String? {
let regex = try! NSRegularExpression(
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,

View File

@ -8,12 +8,37 @@
import Foundation
/**
This `Decodable` class is used to directly map `composer.json`
to this object.
*/
struct ComposerJson: Decodable {
// MARK: - JSON structure
let dependencies: Dictionary<String, String>?
let devDependencies: Dictionary<String, String>?
let configuration: Config?
private enum CodingKeys: String, CodingKey {
case dependencies = "require"
case devDependencies = "require-dev"
case configuration = "config"
}
struct Config: Decodable {
let platform: Platform?
}
struct Platform: Decodable {
let php: String?
}
// MARK: - Helpers
/**
Checks what the PHP version constraint is.
Returns a tuple (constraint, location of constraint).
*/
public func getPhpVersion() -> (String, String) {
// Check if in platform
if configuration?.platform?.php != nil {
@ -29,7 +54,6 @@ struct ComposerJson: Decodable {
return ("", "unknown")
}
/**
Checks if any notable dependencies can be resolved.
Only notable dependencies are saved.
@ -49,19 +73,6 @@ struct ComposerJson: Decodable {
return notable
}
private enum CodingKeys: String, CodingKey {
case dependencies = "require"
case devDependencies = "require-dev"
case configuration = "config"
}
struct Config: Decodable {
let platform: Platform?
}
struct Platform: Decodable {
let php: String?
}
}

View File

@ -9,6 +9,16 @@
import Foundation
import Cocoa
/**
The ServicesView is an example of a view that I consider to be "poorly" set up.
Why ship it like this, then? Well, it works that's reason number one, really.
However, I do believe this should be refactored at some point. Here's why:
this view is responsible for retaining the information about the services status.
The status of the services should live somewhere else, and the fetching of said
service information should also not happen in a view. Yet here we are.
*/
class ServicesView: NSView, XibLoadable {
@IBOutlet weak var imageViewPhp: NSImageView!
@ -44,6 +54,7 @@ class ServicesView: NSView, XibLoadable {
self.loadData()
}
// TODO: (5.1) Move data fetching, caching & retrieval somewhere else
func loadData() {
// Use stale data
self.applyAllInfoFieldsFromCachedValue()

View File

@ -15,5 +15,6 @@ struct Preview_Previews: PreviewProvider {
PMHeaderView(content: "You are running PHP 8.1")
PMStatsView(content: "15 MB")
PMStatsView(content: "2 GB")
PMServicesView() // uses live services data!
}
}