mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-23 20:00:05 +01:00
✏️ New comments
This commit is contained in:
@@ -8,8 +8,8 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `Paths` class is used to locate various binaries on the system,
|
The `Paths` class is used to locate various binaries on the system.
|
||||||
and provides a full
|
The path to the Homebrew directory and the user's name are fetched only once, at boot.
|
||||||
*/
|
*/
|
||||||
public class Paths {
|
public class Paths {
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
|
|
||||||
import Foundation
|
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 = {})
|
public func runAsync(_ execute: @escaping () -> Void, completion: @escaping () -> Void = {})
|
||||||
{
|
{
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ class MenuBarImageGenerator {
|
|||||||
return targetImage
|
return targetImage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The same as before, but also attempts to add an icon to the left.
|
||||||
|
*/
|
||||||
public static func textToImageWithIcon(text: String) -> NSImage {
|
public static func textToImageWithIcon(text: String) -> NSImage {
|
||||||
let textImage = self.textToImage(text: text)
|
let textImage = self.textToImage(text: text)
|
||||||
let iconImage = NSImage(named: "StatusBarPHP")!
|
let iconImage = NSImage(named: "StatusBarPHP")!
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import Foundation
|
|||||||
|
|
||||||
class VersionExtractor {
|
class VersionExtractor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
This attempts to extract the version number from the command line output of Valet.
|
||||||
|
*/
|
||||||
public static func from(_ string: String) -> String? {
|
public static func from(_ string: String) -> String? {
|
||||||
let regex = try! NSRegularExpression(
|
let regex = try! NSRegularExpression(
|
||||||
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,
|
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,
|
||||||
|
|||||||
@@ -8,12 +8,37 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
/**
|
||||||
|
This `Decodable` class is used to directly map `composer.json`
|
||||||
|
to this object.
|
||||||
|
*/
|
||||||
struct ComposerJson: Decodable {
|
struct ComposerJson: Decodable {
|
||||||
|
|
||||||
|
// MARK: - JSON structure
|
||||||
|
|
||||||
let dependencies: Dictionary<String, String>?
|
let dependencies: Dictionary<String, String>?
|
||||||
let devDependencies: Dictionary<String, String>?
|
let devDependencies: Dictionary<String, String>?
|
||||||
let configuration: Config?
|
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) {
|
public func getPhpVersion() -> (String, String) {
|
||||||
// Check if in platform
|
// Check if in platform
|
||||||
if configuration?.platform?.php != nil {
|
if configuration?.platform?.php != nil {
|
||||||
@@ -29,7 +54,6 @@ struct ComposerJson: Decodable {
|
|||||||
return ("", "unknown")
|
return ("", "unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if any notable dependencies can be resolved.
|
Checks if any notable dependencies can be resolved.
|
||||||
Only notable dependencies are saved.
|
Only notable dependencies are saved.
|
||||||
@@ -49,19 +73,6 @@ struct ComposerJson: Decodable {
|
|||||||
return notable
|
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?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,16 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Cocoa
|
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 {
|
class ServicesView: NSView, XibLoadable {
|
||||||
|
|
||||||
@IBOutlet weak var imageViewPhp: NSImageView!
|
@IBOutlet weak var imageViewPhp: NSImageView!
|
||||||
@@ -44,6 +54,7 @@ class ServicesView: NSView, XibLoadable {
|
|||||||
self.loadData()
|
self.loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: (5.1) Move data fetching, caching & retrieval somewhere else
|
||||||
func loadData() {
|
func loadData() {
|
||||||
// Use stale data
|
// Use stale data
|
||||||
self.applyAllInfoFieldsFromCachedValue()
|
self.applyAllInfoFieldsFromCachedValue()
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ struct Preview_Previews: PreviewProvider {
|
|||||||
PMHeaderView(content: "You are running PHP 8.1")
|
PMHeaderView(content: "You are running PHP 8.1")
|
||||||
PMStatsView(content: "15 MB")
|
PMStatsView(content: "15 MB")
|
||||||
PMStatsView(content: "2 GB")
|
PMStatsView(content: "2 GB")
|
||||||
|
PMServicesView() // uses live services data!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user