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

🔥 WIP: Removed broken view

This commit is contained in:
2022-12-20 19:42:27 +01:00
parent ff7c68ddfb
commit 923f0237e8
3 changed files with 15 additions and 129 deletions

View File

@ -2749,7 +2749,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 900;
CURRENT_PROJECT_VERSION = 1000;
DEAD_CODE_STRIPPING = YES;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787;
@ -2778,7 +2778,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 900;
CURRENT_PROJECT_VERSION = 1000;
DEAD_CODE_STRIPPING = YES;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787;
@ -3006,7 +3006,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 900;
CURRENT_PROJECT_VERSION = 1000;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES;
@ -3116,7 +3116,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 900;
CURRENT_PROJECT_VERSION = 1000;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES;

View File

@ -13,11 +13,9 @@ class ServicesManager: ObservableObject {
static var shared = ServicesManager()
#warning("Only publish the status")
@Published private(set) var formulae: [HomebrewFormula]
private(set) var formulae: [HomebrewFormula]
private(set) var services: [String: ServiceWrapper] = [:]
@Published private(set) var services: [String: ServiceWrapper] = [:]
init() {
Log.info("Initializing ServicesManager...")

View File

@ -10,154 +10,42 @@ import Foundation
import SwiftUI
struct ServicesView: View {
@ObservedObject var manager: ServicesManager
@State var servicesToDisplay: [String]
@State var perRow: Int = 3
static func asMenuItem(perRow: Int = 3) -> NSMenuItem {
let item = NSMenuItem()
let services = ServicesManager.shared.formulae.map { formula in
return formula.name
}
let view = NSHostingView(
rootView: Self(
manager: ServicesManager.shared,
servicesToDisplay: services,
perRow: perRow
)
rootView: Self()
)
view.autoresizingMask = [.width, .height]
let height = CGFloat(45 * services.chunked(by: perRow).count)
let height = CGFloat(45 * ["a", "b", "c", "d", "e", "f"]
.chunked(by: perRow).count)
view.setFrameSize(CGSize(width: view.frame.width, height: height))
item.view = view
return item
}
var body: some View {
VStack(alignment: .leading, spacing: 10) {
ForEach(servicesToDisplay.chunked(by: self.perRow), id: \.self) { chunk in
HStack {
ForEach(0...self.perRow - 1, id: \.self) { index in
if chunk.indices.contains(index) {
// A service exists to fill the cell
let service = chunk[index]
VStack(alignment: .center, spacing: 3) {
SectionHeaderView(text: service.uppercased())
CheckmarkView(serviceName: service)
.environmentObject(manager)
}.frame(minWidth: 0, maxWidth: .infinity)
} else {
// Empty cell
VStack {
EmptyView()
}.frame(minWidth: 0, maxWidth: .infinity)
}
}
}
}
}
Text("WIP")
.padding(10)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.debug)
}
}
struct CheckmarkView: View {
@State var serviceName: String
@State var busy: Bool = false
@EnvironmentObject var manager: ServicesManager
public func hasAnyServices() -> Bool {
return !manager.services.isEmpty
}
public func active() -> Bool? {
if manager.services.keys.contains(serviceName) {
return manager.services[serviceName]!.service?.running ?? nil
}
return nil
}
public func toggleService() async {
if active()! {
await Actions.stopService(name: serviceName)
await delay(seconds: 1.2)
busy = false
} else {
await Actions.startService(name: serviceName)
await delay(seconds: 1.2)
busy = false
}
}
var body: some View {
if !hasAnyServices() {
Image(systemName: "hourglass.circle")
.resizable()
.frame(width: 16.0, height: 16.0)
.foregroundColor(.appSecondary)
} else {
if busy {
ProgressView()
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
.frame(width: 16.0, height: 20.0)
} else if active() == nil {
Button { } label: {
Text("?")
}.disabled(true)
} else {
Button {
busy = true
Task { await toggleService() }
} label: {
Image(systemName: active()! ? "checkmark" : "xmark")
.resizable()
.frame(width: 12.0, height: 12.0)
.foregroundColor(active()! ? Color.primary : Color("IconColorRed"))
}
}
}
}
}
struct ServicesView_Previews: PreviewProvider {
static var previews: some View {
ServicesView(
manager: ServicesManager()
.withDummyServices([:]),
servicesToDisplay: ["php", "nginx", "dnsmasq"]
)
ServicesView()
.frame(width: 330.0)
.previewDisplayName("Loading")
ServicesView(
manager: ServicesManager()
.withDummyServices([
"php": false,
"nginx": true,
"dnsmasq": true
]),
servicesToDisplay: ["php", "nginx", "dnsmasq"]
)
ServicesView()
.frame(width: 330.0)
.previewDisplayName("Light Mode")
ServicesView(
manager: ServicesManager()
.withDummyServices([
"php": false,
"nginx": true,
"dnsmasq": true,
"mysql": false
]),
servicesToDisplay: ["php", "nginx", "dnsmasq",
"mysql", "redis", "php@7.4"],
perRow: 3
)
ServicesView()
.frame(width: 330.0)
.previewDisplayName("Dark Mode")
.preferredColorScheme(.dark)