Files
iKeyMon/Sources/Views/Tabs/ResourcesView.swift
2026-04-19 11:33:15 +02:00

121 lines
3.8 KiB
Swift

//
// RecourcesView.swift
// iKeyMon
//
// Created by tracer on 31.03.25.
//
//
// GeneralTab.swift
// iKeyMon
//
// Created by tracer on 30.03.25.
//
import SwiftUI
struct ResourcesView: View {
@Binding var server: Server
private var displayInfo: ServerInfo {
server.info ?? .placeholder
}
var body: some View {
GeometryReader { geometry in
ScrollView {
VStack(alignment: .leading, spacing: 6) {
TableRowView {
Text("CPU Load")
} value: {
LoadBarCell(
percent: displayInfo.load.percent,
load1: displayInfo.load.minute1,
load5: displayInfo.load.minute5,
load15: displayInfo.load.minute15
)
}
TableRowView {
Text("Memory")
} value: {
UsageBarCell(
free: displayInfo.memory.free,
used: displayInfo.memory.used,
total: displayInfo.memory.total,
percent: displayInfo.memory.percent
)
}
TableRowView {
Text("Swap")
} value: {
UsageBarCell(
free: displayInfo.swap.free,
used: displayInfo.swap.used,
total: displayInfo.swap.total,
percent: displayInfo.swap.percent
)
}
TableRowView {
Text("SSD")
} value: {
UsageBarCell(
free: displayInfo.diskSpace.free,
used: displayInfo.diskSpace.used,
total: displayInfo.diskSpace.total,
percent: displayInfo.diskSpace.percent
)
}
}
.padding()
.frame(minHeight: geometry.size.height, alignment: .top)
}
}
// VStack(alignment: .leading, spacing: 16) {
// if let info = server.info {
// Text("Server Utilization")
// .font(.headline)
// .padding(.bottom, 4)
//
// ResourceRow(label: "CPU Load", value: "\(info.load.percent)", subtext: info.cpuLoadDetail)
// ResourceRow(label: "Process Count", value: "\(info.processCount)")
//// ResourceRow(label: "Emails in Queue", value: "\(info.emailsInQueue)")
//
// ResourceBarRow(
// label: "Memory",
// free: info.memory.free,
// used: info.memory.used,
// total: info.memory.total,
// percent: info.memory.percent
// )
//
// ResourceBarRow(
// label: "Swap",
// free: info.memory.free,
// used: info.memory.used,
// total: info.memory.total,
// percent: info.memory.percent
// )
//
// Spacer()
// } else {
// Text("No data")
// }
// }
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
}
#Preview {
struct PreviewWrapper: View {
@State var previewServer = Server(hostname: "example.com", info: .placeholder)
var body: some View {
ResourcesView(server: $previewServer)
}
}
return PreviewWrapper()
}