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

🏗 WIP: Services rewrite

This commit is contained in:
2022-12-19 18:09:10 +01:00
parent bf2c0c259f
commit ff7c68ddfb
3 changed files with 28 additions and 6 deletions

View File

@ -3019,7 +3019,7 @@
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 5.7;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev;
PRODUCT_NAME = "$(TARGET_NAME)";
PRODUCT_NAME = "$(TARGET_NAME) DEV";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};

View File

@ -13,9 +13,11 @@ class ServicesManager: ObservableObject {
static var shared = ServicesManager()
private var formulae: [HomebrewFormula]
#warning("Only publish the status")
@Published var services: [String: ServiceWrapper] = [:]
private(set) var formulae: [HomebrewFormula]
private(set) var services: [String: ServiceWrapper] = [:]
init() {
Log.info("Initializing ServicesManager...")
@ -35,7 +37,27 @@ class ServicesManager: ObservableObject {
services = Dictionary(uniqueKeysWithValues: formulae.map { ($0.name, ServiceWrapper(formula: $0)) })
}
public func updateServicesList() async {
Task { @MainActor in
formulae = [
Homebrew.Formulae.php,
Homebrew.Formulae.nginx,
Homebrew.Formulae.dnsmasq
]
let additionalFormulae = (Preferences.custom.services ?? []).map({ item in
return HomebrewFormula(item, elevated: false)
})
formulae.append(contentsOf: additionalFormulae)
services = Dictionary(uniqueKeysWithValues: formulae.map { ($0.name, ServiceWrapper(formula: $0)) })
}
}
public static func loadHomebrewServices() async {
await Self.shared.updateServicesList()
Task {
let rootServiceNames = Self.shared.formulae
.filter { $0.elevated }

View File

@ -17,9 +17,9 @@ struct ServicesView: View {
static func asMenuItem(perRow: Int = 3) -> NSMenuItem {
let item = NSMenuItem()
let services = ServicesManager.shared.services.keys.map({ item in
return item
})
let services = ServicesManager.shared.formulae.map { formula in
return formula.name
}
let view = NSHostingView(
rootView: Self(