69 lines
3.3 KiB
Swift
69 lines
3.3 KiB
Swift
import SwiftUI
|
|
|
|
struct StorageDetailsView: View {
|
|
let disk: DiskMetrics?
|
|
let health: DiskHealthMetrics?
|
|
let showVolumes: () -> Void
|
|
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
|
private let color = Color("MetricDisk")
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Divider()
|
|
HStack {
|
|
Text("disk.distribution").fontWeight(.semibold).help(Text("disk.capacityScope"))
|
|
Spacer()
|
|
Text("disk.utilization").foregroundStyle(.secondary)
|
|
AnimatedMetricText(value: MetricFormat.percent(disk?.usage)).foregroundStyle(color)
|
|
}
|
|
GeometryReader { proxy in
|
|
ZStack(alignment: .leading) {
|
|
Rectangle().fill(Color("MemoryAvailable"))
|
|
Rectangle().fill(color)
|
|
.frame(width: proxy.size.width * CGFloat(disk?.usage ?? 0))
|
|
}
|
|
// Clip the whole track, with no minimum fill width for tiny values.
|
|
.clipShape(Capsule())
|
|
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: disk?.usage)
|
|
}.frame(height: 7).accessibilityHidden(true)
|
|
HStack {
|
|
capacity("disk.used", value: disk.map { $0.total - min($0.total, $0.available) }, tint: color)
|
|
capacity("memory.available", value: disk?.available, tint: Color("MemoryAvailable"))
|
|
}
|
|
Divider()
|
|
HStack(alignment: .top, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text("disk.remainingLife").foregroundStyle(.secondary)
|
|
AnimatedMetricText(value: MetricFormat.percent(health?.remainingLife))
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
Divider().frame(height: 30)
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text("disk.powerOnHours").foregroundStyle(.secondary)
|
|
AnimatedMetricText(value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
Divider().frame(height: 30)
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text("disk.localVolumes").foregroundStyle(.secondary)
|
|
Button(action: showVolumes) {
|
|
HStack(spacing: 2) {
|
|
Text("disk.viewDetails")
|
|
Image(systemName: "chevron.right").font(.system(size: 8))
|
|
}
|
|
}.buttonStyle(.plain)
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
|
}.padding(.top, 3)
|
|
}
|
|
|
|
private func capacity(_ title: LocalizedStringKey, value: UInt64?, tint: Color) -> some View {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
HStack(spacing: 4) {
|
|
Circle().fill(tint).frame(width: 4, height: 4)
|
|
Text(title).foregroundStyle(.secondary)
|
|
}
|
|
AnimatedMetricText(value: MetricFormat.bytes(value)).fontWeight(.medium)
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
.font(.system(size: 10)).lineLimit(1)
|
|
}
|
|
}
|