refactor(ui): 统一资源卡片规范并收敛面板布局与公共组件
This commit is contained in:
@@ -21,7 +21,7 @@ struct GPUStatisticsView: View {
|
||||
MetricRingGauge(title: "gpu.recentAverage", value: average, color: Color("MetricCPU"))
|
||||
MetricRingGauge(title: "gpu.peak", value: peak, color: Color("MetricGPU"))
|
||||
}.frame(maxWidth: .infinity).help(Text("gpu.summaryHelp"))
|
||||
}.frame(height: 42)
|
||||
}.frame(height: 46)
|
||||
}
|
||||
|
||||
private func memoryRow(_ title: LocalizedStringKey, bytes: UInt64?, color: Color) -> some View {
|
||||
@@ -29,8 +29,8 @@ struct GPUStatisticsView: View {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 0)
|
||||
AnimatedMetricText(value: MetricFormat.bytes(bytes)).fontWeight(.medium)
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
AnimatedMetricText(value: MetricFormat.bytes(bytes)).font(PanelStyle.value)
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
MetricProgressBar(value: bytes.map { Double($0) / reference } ?? 0, color: color)
|
||||
.frame(height: 3)
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: bytes)
|
||||
|
||||
@@ -2,62 +2,34 @@ import SwiftUI
|
||||
|
||||
struct MemoryDetailsView: View {
|
||||
let memory: MemoryMetrics
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
private var colors: [Color] { [Color("MemoryApplication"), Color("MemoryWired"), Color("MemoryCompressed"), Color("MemoryAvailable")] }
|
||||
private var values: [UInt64] { [memory.app, memory.wired, memory.compressed, memory.available] }
|
||||
private let labels: [LocalizedStringKey] = ["memory.app", "memory.wired", "memory.compressed", "memory.available"]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 9) {
|
||||
Divider()
|
||||
HStack {
|
||||
Text("memory.distribution").fontWeight(.semibold)
|
||||
Spacer()
|
||||
Text("gpu.totalUtilization").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.percent(memory.usage)).foregroundStyle(Color("MemoryApplication"))
|
||||
}
|
||||
GeometryReader { proxy in
|
||||
HStack(spacing: 0) {
|
||||
ForEach(0..<4) { index in
|
||||
Rectangle().fill(colors[index])
|
||||
.frame(width: CGFloat(values[index]) / CGFloat(max(1, memory.total)) * proxy.size.width)
|
||||
}
|
||||
}
|
||||
// Round the combined shape; tiny segments never receive a minimum width.
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
||||
}.frame(height: 8).accessibilityHidden(true)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
CardSeparator()
|
||||
CardSectionHeader(title: "memory.distribution", valueLabel: "gpu.totalUtilization",
|
||||
value: MetricFormat.percent(memory.usage), color: Color("MemoryApplication"))
|
||||
CapacityBar(values: values.map { Double($0) }, colors: colors, total: Double(memory.total))
|
||||
HStack(spacing: 4) {
|
||||
ForEach(0..<4) { index in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(colors[index]).frame(width: 4, height: 4)
|
||||
Text(labels[index]).foregroundStyle(.secondary)
|
||||
}
|
||||
AnimatedMetricText(value: MetricFormat.memory(values[index]))
|
||||
.fontWeight(.medium).monospacedDigit()
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
CapacityField(title: labels[index], value: MetricFormat.memory(values[index]), color: colors[index])
|
||||
}
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
Divider()
|
||||
}
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.pressure").foregroundStyle(.secondary)
|
||||
pressure
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.cached").foregroundStyle(.secondary)
|
||||
CardField(title: "memory.pressure") { pressure }
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.cached") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.cached))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.help(Text("memory.cachedHelp"))
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.swap").foregroundStyle(.secondary)
|
||||
}.help(Text("memory.cachedHelp"))
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.swap") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
}.padding(.top, 4)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private var pressure: some View {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
extension MenuPanelView {
|
||||
var networkCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: "↓ " + MetricFormat.rate(total(\.download)),
|
||||
secondaryValue: "↑ " + MetricFormat.rate(total(\.upload)), valueColor: Color("MetricMemory"),
|
||||
secondaryValueColor: Color("SeriesUpload")
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"),
|
||||
secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, showsLegendValues: false
|
||||
).id(selectedInterface)
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
networkTotal(
|
||||
"network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }),
|
||||
symbol: "arrow.down", color: Color("MetricMemory"))
|
||||
Divider().frame(height: 32)
|
||||
networkTotal(
|
||||
"network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }),
|
||||
symbol: "arrow.up", color: Color("SeriesUpload"))
|
||||
Divider().frame(height: 32)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("network.status").foregroundStyle(.secondary)
|
||||
Picker("panel.interface", selection: $selectedInterface) {
|
||||
Text("network.all").tag("")
|
||||
ForEach(snapshot.network ?? [], id: \.identity) { item in
|
||||
Text(verbatim: item.name).tag(item.identity)
|
||||
}
|
||||
}.labelsHidden().controlSize(.mini).fixedSize()
|
||||
}
|
||||
HStack(spacing: 4) {
|
||||
Circle().fill(networkStatusColor).frame(width: 5, height: 5)
|
||||
Text(networkStatusLabel)
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
CardSeparator()
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("network.addresses").font(PanelStyle.section)
|
||||
HStack(spacing: 8) {
|
||||
networkAddress("network.public", address: publicIPAddress)
|
||||
Divider().frame(height: 15)
|
||||
networkAddress(
|
||||
"network.local",
|
||||
address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first)
|
||||
}
|
||||
}.font(PanelStyle.label)
|
||||
.modifier(CardInset())
|
||||
}
|
||||
.task(id: publicIPRoute) {
|
||||
publicIPAddress = nil
|
||||
guard snapshot.networkPath == .available else { return }
|
||||
let address = await PublicIPAddressService.shared.address(route: publicIPRoute)
|
||||
guard !Task.isCancelled else { return }
|
||||
publicIPAddress = address
|
||||
}
|
||||
}
|
||||
var publicIPRoute: String {
|
||||
"\(snapshot.defaultNetworkInterface ?? ""):\(String(describing: snapshot.networkPath)):\(snapshot.network?.filter { $0.active }.map { $0.addresses.joined(separator: ",") }.joined(separator: ";") ?? "")"
|
||||
}
|
||||
func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Text(verbatim: address ?? "--").font(PanelStyle.value).monospacedDigit().textSelection(.enabled)
|
||||
.help(Text(verbatim: address ?? "--"))
|
||||
Spacer(minLength: 0)
|
||||
if let address {
|
||||
Button {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(address, forType: .string)
|
||||
} label: {
|
||||
Image(systemName: "doc.on.doc")
|
||||
}
|
||||
.buttonStyle(.plain).accessibilityLabel(Text("panel.copy"))
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading).lineLimit(1)
|
||||
}
|
||||
func networkTotal(_ title: LocalizedStringKey, value: String, symbol: String, color: Color) -> some View {
|
||||
CardField(title: title) {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
AnimatedMetricText(value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var networkStatusLabel: LocalizedStringKey {
|
||||
switch snapshot.networkPath {
|
||||
case .available: "network.pathAvailable"
|
||||
case .unavailable: "network.pathUnavailable"
|
||||
case .requiresConnection: "network.pathRequiresConnection"
|
||||
case nil: "metric.waiting"
|
||||
}
|
||||
}
|
||||
var networkStatusColor: Color {
|
||||
switch snapshot.networkPath {
|
||||
case .available: .green
|
||||
case .unavailable: .red
|
||||
case .requiresConnection: .orange
|
||||
case nil: .secondary
|
||||
}
|
||||
}
|
||||
var addressInterface: NetworkInterfaceMetrics? {
|
||||
let name = selectedInterface.isEmpty ? snapshot.defaultNetworkInterface : network.first?.name
|
||||
return snapshot.network?.first { $0.name == name && $0.active }
|
||||
}
|
||||
var networkIntervals: [TimeInterval] {
|
||||
selectedInterface.isEmpty ? chartIntervals : (metrics.history.interfaces[selectedInterface] ?? []).map(\.expectedInterval)
|
||||
}
|
||||
var networkDates: [Date] {
|
||||
selectedInterface.isEmpty ? samples.map(\.date) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.date)
|
||||
}
|
||||
var networkDownloads: [Double?] {
|
||||
selectedInterface.isEmpty ? samples.map(\.download) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.download)
|
||||
}
|
||||
var networkUploads: [Double?] {
|
||||
selectedInterface.isEmpty ? samples.map(\.upload) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.upload)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
extension MenuPanelView {
|
||||
func line(_ key: LocalizedStringKey, _ value: String) -> some View {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text(key).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 6)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value)
|
||||
}.frame(height: 14)
|
||||
}
|
||||
|
||||
func batteryPowerLabel(_ battery: BatteryMetrics) -> LocalizedStringKey {
|
||||
if battery.charging { return "battery.chargePower" }
|
||||
if !battery.externalPower { return "battery.dischargePower" }
|
||||
return "battery.power"
|
||||
}
|
||||
|
||||
var cpuCard: some View {
|
||||
let temperature = snapshot.cpuTemperature
|
||||
let highTemperature = CPUTemperatureMonitor.isHighTemperature(temperature)
|
||||
return ResourceCard(
|
||||
title: "metric.cpu", symbol: "cpu", color: Color("MetricCPU"),
|
||||
value: MetricFormat.percent(snapshot.cpu?.usage),
|
||||
status: temperature.map { "\(Int($0.rounded()))°C" },
|
||||
statusWarning: highTemperature,
|
||||
statusHelp: temperature == nil ? nil : Text("cpu.temperature.help", tableName: "CPUDetails"),
|
||||
warningText: highTemperature ? Text("cpu.temperature.high", tableName: "CPUDetails") : nil
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.cpu),
|
||||
second: samples.map(\.cpuUser), third: samples.map(\.cpuSystem),
|
||||
color: Color("MetricCPU"), secondColor: Color("SeriesUser"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "cpu.user", thirdLabel: "cpu.system", expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
CardSeparator()
|
||||
if let cpu = snapshot.cpu {
|
||||
Spacer(minLength: 0)
|
||||
CPUCoreGrid(
|
||||
values: cpu.cores, kinds: CPUCoreTopology.cores, interval: chartInterval,
|
||||
availableWidth: cardContentWidth)
|
||||
|
||||
} else {
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
CardSeparator()
|
||||
HStack(spacing: 10) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("cpu.load.oneMinute", tableName: "CPUDetails").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 3)
|
||||
AnimatedMetricText(
|
||||
value: snapshot.load.first.map { "\(MetricFormat.decimal($0)) / \(snapshot.cpu?.cores.count ?? 0)" } ?? "--")
|
||||
}
|
||||
MetricProgressBar(
|
||||
value: (snapshot.load.first ?? 0) / Double(max(1, snapshot.cpu?.cores.count ?? 0)), color: Color("MetricCPU")
|
||||
)
|
||||
.frame(height: 5).accessibilityHidden(true)
|
||||
}.frame(maxWidth: .infinity).help(Text("cpu.load.help", tableName: "CPUDetails"))
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 25)
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text("panel.uptime").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
.fontWeight(.medium)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
|
||||
}
|
||||
}
|
||||
var gpuCard: some View {
|
||||
let summary = GPUUtilizationSummary(samples: samples)
|
||||
return ResourceCard(
|
||||
title: "metric.gpu", symbol: "square.grid.2x2", color: Color("MetricGPU"), value: MetricFormat.percent(snapshot.gpuUsage),
|
||||
status: snapshot.gpuTemperature.map { "\(Int($0.rounded()))°C" },
|
||||
statusHelp: Text("gpu.temperatureHelp"),
|
||||
detail: snapshot.gpu?.coreCount.map { String(format: String(localized: "gpu.coreCountFormat"), $0) }
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.gpu),
|
||||
second: samples.map(\.gpuRenderer), third: samples.map(\.gpuTiler),
|
||||
color: Color("MetricGPU"), secondColor: Color("MetricCPU"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "gpu.renderer", thirdLabel: "gpu.tiler",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
CardSeparator()
|
||||
gpuActivity("gpu.rendererActivity", value: snapshot.gpu?.renderer, color: Color("MetricCPU"))
|
||||
gpuActivity("gpu.tilerActivity", value: snapshot.gpu?.tiler, color: Color("SeriesSystem"))
|
||||
CardSeparator()
|
||||
Spacer(minLength: 0)
|
||||
GPUStatisticsView(
|
||||
inUse: snapshot.gpu?.inUseMemory, allocated: snapshot.gpu?.allocatedMemory,
|
||||
average: summary.average, peak: summary.peak
|
||||
)
|
||||
.help(snapshot.gpuUsage == nil ? Text("gpu.unavailable") : Text("gpu.summaryHelp"))
|
||||
Spacer(minLength: 0)
|
||||
let fans = displayedFans
|
||||
if !fans.isEmpty {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 5) {
|
||||
ForEach(fans) { fan in
|
||||
FanSpeedIndicator(
|
||||
title: fans.count == 2
|
||||
? (fan.id == 0 ? "gpu.fanLeft" : "gpu.fanRight")
|
||||
: LocalizedStringKey("\(String(localized: "gpu.fan")) \(fan.id + 1)"), rpm: fan.rpm)
|
||||
}
|
||||
}
|
||||
.modifier(CardInset())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func gpuActivity(_ title: LocalizedStringKey, value: Double?, color: Color) -> some View {
|
||||
HStack(spacing: 8) {
|
||||
Text(title).font(PanelStyle.label).frame(width: 100, alignment: .leading).help(Text(title))
|
||||
MetricProgressBar(value: value ?? 0, color: color).frame(height: 5)
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
|
||||
AnimatedMetricText(value: MetricFormat.percent(value)).font(PanelStyle.value).frame(width: 30, alignment: .trailing)
|
||||
}.font(PanelStyle.label).help(Text("gpu.pipelineHelp"))
|
||||
}
|
||||
var memoryCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.memory", symbol: "memorychip", color: Color("MemoryApplication"),
|
||||
value: snapshot.memory.map {
|
||||
String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824)
|
||||
} ?? "--"
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
|
||||
second: samples.map(\.memoryApp), third: samples.map(\.memoryWired), fourth: samples.map(\.memoryCompressed),
|
||||
color: Color("MetricCPU"), secondColor: Color("MemoryApplication"),
|
||||
thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1),
|
||||
scaleLabel: MetricFormat.memory(snapshot.memory?.total), firstValueFormat: .memory, firstLabel: "gpu.totalUtilization",
|
||||
secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
if let memory = snapshot.memory {
|
||||
MemoryDetailsView(memory: memory)
|
||||
} else {
|
||||
CardSeparator()
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
var diskCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.disk", symbol: "internaldrive", color: Color("MetricDisk"),
|
||||
value: snapshot.disk.map {
|
||||
String(
|
||||
format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000,
|
||||
Double($0.total) / 1_000_000_000)
|
||||
} ?? "--"
|
||||
) {
|
||||
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"),
|
||||
secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals
|
||||
)
|
||||
.help(Text("disk.physicalIO"))
|
||||
StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth) {
|
||||
showVolumes.toggle()
|
||||
}
|
||||
.popover(isPresented: $showVolumes) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("disk.homeVolume")
|
||||
Text("panel.smartScope").foregroundStyle(.secondary)
|
||||
Group {
|
||||
ForEach(snapshot.volumes ?? [], id: \.path) { volume in
|
||||
VStack(alignment: .leading) {
|
||||
Text(verbatim: volume.name).lineLimit(1).truncationMode(.middle)
|
||||
line(
|
||||
"memory.available",
|
||||
"\(MetricFormat.bytes(volume.capacity.available)) / \(MetricFormat.bytes(volume.capacity.total))")
|
||||
}
|
||||
}
|
||||
Text("panel.apfsScope").font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
}
|
||||
}.padding(12).frame(width: 330)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
var batteryCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"),
|
||||
value: MetricFormat.percent(snapshot.battery?.charge)
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map(\.battery),
|
||||
second: samples.map(\.batteryPower),
|
||||
color: Color("MetricBattery"),
|
||||
secondColor: Color("SeriesUser"),
|
||||
fixedScale: 1,
|
||||
secondSeriesUsesAutonomousScale: true,
|
||||
secondValueFormat: .watts,
|
||||
firstLabel: "metric.battery",
|
||||
secondLabel: snapshot.battery.map(batteryPowerLabel) ?? "battery.power",
|
||||
expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries,
|
||||
intervals: chartIntervals
|
||||
)
|
||||
CardSeparator()
|
||||
if let battery = snapshot.battery {
|
||||
batteryDetails(battery)
|
||||
} else {
|
||||
Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
private func batteryDetails(_ battery: BatteryMetrics) -> some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
VStack(spacing: 4) {
|
||||
line("battery.health", MetricFormat.percent(battery.health))
|
||||
HStack {
|
||||
Text("battery.powerSource").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
Text(battery.externalPower ? "battery.acPower" : "battery.batterySource").font(PanelStyle.value)
|
||||
}.frame(height: 14)
|
||||
}
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 32)
|
||||
VStack(spacing: 4) {
|
||||
line("battery.cycles", battery.cycles.map(String.init) ?? "--")
|
||||
HStack {
|
||||
Text("battery.timeEstimate").foregroundStyle(.secondary).help(Text("battery.timeEstimate"))
|
||||
Spacer(minLength: 4)
|
||||
if battery.externalPower {
|
||||
Text("battery.timeNotApplicable").font(PanelStyle.value).help(Text("battery.timeNotApplicable"))
|
||||
} else if let minutes = battery.minutesRemaining {
|
||||
AnimatedMetricText(value: "\(minutes) min").font(PanelStyle.value)
|
||||
} else {
|
||||
Text("battery.timeUnknown").font(PanelStyle.value)
|
||||
}
|
||||
}.frame(height: 14)
|
||||
}
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.lineLimit(1)
|
||||
.frame(height: 32)
|
||||
Spacer(minLength: 0)
|
||||
CardSeparator()
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("battery.highestEnergyProcess").font(PanelStyle.section)
|
||||
Spacer()
|
||||
Text("battery.cpuUsage").foregroundStyle(.secondary)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
let energyProcesses = snapshot.processes?.highestCPUProcesses(limit: 3) ?? []
|
||||
if energyProcesses.isEmpty {
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
} else {
|
||||
ForEach(energyProcesses) { process in
|
||||
EnergyProcessListRow(process: process)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reserve the header and all three rows before process sampling completes.
|
||||
.frame(height: 74, alignment: .top)
|
||||
.lineLimit(1)
|
||||
.help(Text("battery.energyProxyHelp"))
|
||||
|
||||
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct EnergyProcessListRow: View {
|
||||
let process: ProcessMetrics
|
||||
@State private var icon: NSImage?
|
||||
|
||||
private var progress: Double {
|
||||
guard let value = process.cpu, value.isFinite else { return 0 }
|
||||
return min(max(value, 0), 1)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
Group {
|
||||
if let icon {
|
||||
Image(nsImage: icon).resizable().interpolation(.high)
|
||||
} else {
|
||||
Image(systemName: "app.dashed").resizable().scaledToFit().padding(2)
|
||||
}
|
||||
}
|
||||
.frame(width: 15, height: 15)
|
||||
.accessibilityHidden(true)
|
||||
Text(verbatim: process.name).lineLimit(1).truncationMode(.middle)
|
||||
.frame(width: 66, alignment: .leading)
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(.primary.opacity(0.07))
|
||||
.overlay(alignment: .leading) {
|
||||
Capsule().fill(Color("MetricCPU"))
|
||||
.frame(width: proxy.size.width * progress, height: 4)
|
||||
.clipped()
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.frame(height: 4)
|
||||
.animation(.easeInOut(duration: 0.35), value: process.cpu)
|
||||
AnimatedMetricText(value: process.cpu.map { String(format: "%.1f%%", $0 * 100) } ?? "--")
|
||||
.foregroundStyle(Color("MetricCPU")).font(PanelStyle.value)
|
||||
.monospacedDigit().frame(width: 39, alignment: .trailing)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.frame(height: 16)
|
||||
.task(id: process.id) {
|
||||
icon = NSRunningApplication(processIdentifier: process.id.pid)?.icon
|
||||
if icon == nil, let path = process.path {
|
||||
icon = NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,63 +8,68 @@ struct MenuPanelView: View {
|
||||
let settingsPresentation: SettingsPresentation
|
||||
var presentation = PanelPresentation()
|
||||
var onOpenSettings: () -> Void = {}
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@Environment(\.accessibilityReduceMotion) var reduceMotion
|
||||
@State private var panelSize = PanelLayout.contentSize(visible: NSScreen.main?.visibleFrame ?? CGRect(x: 0, y: 0, width: 1000, height: 760))
|
||||
@State private var selectedInterface = ""
|
||||
@State private var publicIPAddress: String?
|
||||
@State private var showVolumes = false
|
||||
@State var selectedInterface = ""
|
||||
@State var publicIPAddress: String?
|
||||
@State var showVolumes = false
|
||||
|
||||
private var snapshot: MetricsSnapshot { metrics.snapshot }
|
||||
private var samples: [TrendSample] { metrics.history.samples }
|
||||
private var chartIntervals: [TimeInterval] { samples.map(\.expectedInterval) }
|
||||
private var chartInterval: TimeInterval { Double(metrics.effectiveMilliseconds) / 1000 }
|
||||
private var chartBoundaries: Set<Date> { Set(samples.filter(\.breakBefore).map(\.date)) }
|
||||
private var columns: Int { panelSize.width >= 1160 ? 3 : panelSize.width >= 900 ? 2 : 1 }
|
||||
private var firstRowHeight: CGFloat {
|
||||
let cardWidth = (panelSize.width - 20 - CGFloat(columns - 1) * 8) / CGFloat(columns)
|
||||
let groups = CPUCoreGrid.groups(count: snapshot.cpu?.cores.count ?? 0, kinds: CPUCoreTopology.cores)
|
||||
let widths = CPUCoreGrid.groupWidths(groups: groups, width: max(0, cardWidth - 20))
|
||||
let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0
|
||||
let extraFanRows = max(0, ((snapshot.fans?.count ?? 0) + 1) / 2 - 1)
|
||||
return max(260 + (coreRows >= 3 ? 26 : 0), 260 + CGFloat(extraFanRows) * 19)
|
||||
var snapshot: MetricsSnapshot { metrics.snapshot }
|
||||
var samples: [TrendSample] { metrics.history.samples }
|
||||
var chartIntervals: [TimeInterval] { samples.map(\.expectedInterval) }
|
||||
var chartInterval: TimeInterval { Double(metrics.effectiveMilliseconds) / 1000 }
|
||||
var chartBoundaries: Set<Date> { Set(samples.filter(\.breakBefore).map(\.date)) }
|
||||
@State private var reservedFanCount = 0
|
||||
@State private var measuredCardWidth: CGFloat?
|
||||
var displayedFans: [FanMetrics] {
|
||||
let fans = snapshot.fans ?? []
|
||||
guard fans.count < reservedFanCount else { return fans }
|
||||
let missingIDs = (0..<reservedFanCount).filter { id in !fans.contains { $0.id == id } }
|
||||
return (fans + missingIDs.prefix(reservedFanCount - fans.count).map { FanMetrics(id: $0, rpm: nil) }).sorted { $0.id < $1.id }
|
||||
}
|
||||
private var network: [NetworkInterfaceMetrics] {
|
||||
var cardContentWidth: CGFloat { max(0, (measuredCardWidth ?? PanelLayout.cardWidth(size: panelSize)) - 20) }
|
||||
var columns: Int { PanelLayout.columns(width: panelSize.width) }
|
||||
private var rowHeights: [CGFloat] {
|
||||
let groups = CPUCoreGrid.groups(count: snapshot.cpu?.cores.count ?? 0, kinds: CPUCoreTopology.cores)
|
||||
let widths = CPUCoreGrid.groupWidths(groups: groups, width: max(0, (measuredCardWidth ?? PanelLayout.cardWidth(size: panelSize)) - 20))
|
||||
let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0
|
||||
return PanelLayout.rowHeights(columns: columns, coreRows: coreRows,
|
||||
fanCount: max(reservedFanCount, snapshot.fans?.count ?? 0))
|
||||
}
|
||||
var network: [NetworkInterfaceMetrics] {
|
||||
(snapshot.network ?? []).filter { selectedInterface.isEmpty ? $0.isIncludedInTotal : $0.identity == selectedInterface }
|
||||
}
|
||||
private func total(_ key: KeyPath<NetworkInterfaceMetrics, Double?>) -> Double? {
|
||||
func total(_ key: KeyPath<NetworkInterfaceMetrics, Double?>) -> Double? {
|
||||
let rates = network.compactMap { $0[keyPath: key] }
|
||||
return !network.isEmpty && rates.count == network.count ? rates.reduce(0, +) : nil
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 8) {
|
||||
VStack(spacing: PanelStyle.gap) {
|
||||
header
|
||||
if columns == 3 {
|
||||
if panelSize.height >= 810 { resourceRows }
|
||||
else { ScrollView { resourceRows } }
|
||||
if PanelLayout.needsResourceScroll(size: panelSize, rows: rowHeights) {
|
||||
ScrollView { resourceRows }
|
||||
.frame(maxHeight: PanelLayout.resourceHeight(rows: rowHeights))
|
||||
} else {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8, alignment: .top), count: columns), spacing: 8) {
|
||||
cpuCard.frame(height: firstRowHeight)
|
||||
gpuCard.frame(height: firstRowHeight)
|
||||
batteryCard.frame(height: firstRowHeight)
|
||||
memoryCard.frame(minHeight: 240)
|
||||
diskCard.frame(minHeight: 250)
|
||||
networkCard.frame(minHeight: 250)
|
||||
}
|
||||
}
|
||||
resourceRows
|
||||
}
|
||||
if metrics.isPanelVisible {
|
||||
ProcessTableView(snapshot: snapshot.processes, wide: panelSize.width >= 900, logicalCPUCount: snapshot.cpu?.cores.count ?? 1).frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(minHeight: 170)
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
.padding(PanelStyle.padding)
|
||||
.frame(width: panelSize.width, height: panelSize.height)
|
||||
.background(PanelWindowObserver { size in
|
||||
if panelSize != size { panelSize = size }
|
||||
}.frame(width: 0, height: 0))
|
||||
.onAppear { metrics.setPanelVisible(true) }
|
||||
.onAppear {
|
||||
metrics.setPanelVisible(true)
|
||||
reservedFanCount = snapshot.fans?.count ?? 0
|
||||
}
|
||||
.onChange(of: snapshot.fans?.count) { _, count in
|
||||
reservedFanCount = max(reservedFanCount, count ?? 0)
|
||||
}
|
||||
.onDisappear { metrics.setPanelVisible(false) }
|
||||
.onChange(of: snapshot.network?.map(\.identity)) { _, keys in
|
||||
if !selectedInterface.isEmpty && !(keys ?? []).contains(selectedInterface) { selectedInterface = "" }
|
||||
@@ -75,17 +80,31 @@ struct MenuPanelView: View {
|
||||
}
|
||||
|
||||
private var resourceRows: some View {
|
||||
VStack(spacing: 8) {
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
cpuCard.frame(width: PanelLayout.cardWidth(size: panelSize), height: firstRowHeight)
|
||||
gpuCard.frame(width: PanelLayout.cardWidth(size: panelSize), height: firstRowHeight)
|
||||
batteryCard.frame(width: PanelLayout.cardWidth(size: panelSize), height: firstRowHeight)
|
||||
}.frame(height: firstRowHeight)
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
memoryCard.frame(width: (panelSize.width - 36) / 3)
|
||||
diskCard.frame(width: (panelSize.width - 36) / 3)
|
||||
networkCard.frame(width: (panelSize.width - 36) / 3)
|
||||
}.frame(height: 240)
|
||||
VStack(spacing: PanelStyle.gap) {
|
||||
ForEach(rowHeights.indices, id: \.self) { row in
|
||||
HStack(spacing: PanelStyle.gap) {
|
||||
ForEach(0..<columns, id: \.self) { column in
|
||||
resourceCard(at: row * columns + column)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: rowHeights[row])
|
||||
.onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in
|
||||
if row == 0 && column == 0 { measuredCardWidth = width }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func resourceCard(at index: Int) -> some View {
|
||||
switch index {
|
||||
case 0: cpuCard
|
||||
case 1: gpuCard
|
||||
case 2: batteryCard
|
||||
case 3: memoryCard
|
||||
case 4: diskCard
|
||||
case 5: networkCard
|
||||
default: EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,343 +131,6 @@ struct MenuPanelView: View {
|
||||
}.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private func chart(_ key: KeyPath<TrendSample, Double?>, color: Color, label: LocalizedStringKey = "panel.total") -> some View {
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map { $0[keyPath: key] }, color: color, firstLabel: label, expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
private func line(_ key: LocalizedStringKey, _ value: String) -> some View {
|
||||
HStack(alignment: .firstTextBaseline) { Text(key).foregroundStyle(.secondary); Spacer(minLength: 6); AnimatedMetricText(value: value) }
|
||||
}
|
||||
|
||||
private func coreColor(_ kind: CPUCoreTopology.Kind?) -> Color {
|
||||
switch kind {
|
||||
case .efficiency: Color("MetricCPU")
|
||||
case .middle: Color("MetricMemory")
|
||||
case .performance: Color("MetricGPU")
|
||||
case nil: .secondary
|
||||
}
|
||||
}
|
||||
|
||||
private func coreLabel(_ kind: CPUCoreTopology.Kind) -> Text {
|
||||
switch kind {
|
||||
case .efficiency: Text("cpu.kind.efficiency", tableName: "CPUDetails")
|
||||
case .middle: Text("cpu.kind.performance", tableName: "CPUDetails")
|
||||
case .performance:
|
||||
CPUCoreTopology.cores.values.contains(.middle)
|
||||
? Text("cpu.kind.super", tableName: "CPUDetails")
|
||||
: Text("cpu.kind.performance", tableName: "CPUDetails")
|
||||
}
|
||||
}
|
||||
|
||||
private func batteryPowerLabel(_ battery: BatteryMetrics) -> LocalizedStringKey {
|
||||
if battery.charging { return "battery.chargePower" }
|
||||
if !battery.externalPower { return "battery.dischargePower" }
|
||||
return "battery.power"
|
||||
}
|
||||
|
||||
private var cpuCard: some View {
|
||||
let temperature = snapshot.cpuTemperature
|
||||
let highTemperature = CPUTemperatureMonitor.isHighTemperature(temperature)
|
||||
return ResourceCard(
|
||||
title: "metric.cpu", symbol: "cpu", color: Color("MetricCPU"),
|
||||
value: MetricFormat.percent(snapshot.cpu?.usage),
|
||||
status: temperature.map { "\(Int($0.rounded()))°C" },
|
||||
statusWarning: highTemperature,
|
||||
statusHelp: temperature == nil ? nil : Text("cpu.temperature.help", tableName: "CPUDetails"),
|
||||
warningText: highTemperature ? Text("cpu.temperature.high", tableName: "CPUDetails") : nil
|
||||
) {
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.cpu),
|
||||
second: samples.map(\.cpuUser), third: samples.map(\.cpuSystem),
|
||||
color: Color("MetricCPU"), secondColor: Color("SeriesUser"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "cpu.user", thirdLabel: "cpu.system", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
if let cpu = snapshot.cpu {
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1).padding(.vertical, 3)
|
||||
Spacer(minLength: 0)
|
||||
CPUCoreGrid(values: cpu.cores, kinds: CPUCoreTopology.cores, interval: chartInterval,
|
||||
availableWidth: max(0, (columns == 3 ? PanelLayout.cardWidth(size: panelSize) : (panelSize.width - 20 - CGFloat(columns - 1) * 8) / CGFloat(columns)) - 20))
|
||||
|
||||
} else { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
Spacer(minLength: 0)
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1).padding(.vertical, 3)
|
||||
HStack(spacing: 10) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("cpu.load.oneMinute", tableName: "CPUDetails").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 3)
|
||||
AnimatedMetricText(value: snapshot.load.first.map { "\(MetricFormat.decimal($0)) / \(snapshot.cpu?.cores.count ?? 0)" } ?? "--")
|
||||
}
|
||||
MetricProgressBar(value: (snapshot.load.first ?? 0) / Double(max(1, snapshot.cpu?.cores.count ?? 0)), color: Color("MetricCPU"))
|
||||
.frame(height: 5).accessibilityHidden(true)
|
||||
}.frame(maxWidth: .infinity).help(Text("cpu.load.help", tableName: "CPUDetails"))
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 25)
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text("panel.uptime").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
.fontWeight(.medium)
|
||||
}
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
private var gpuCard: some View {
|
||||
let summary = GPUUtilizationSummary(samples: samples)
|
||||
return ResourceCard(title: "metric.gpu", symbol: "square.grid.2x2", color: Color("MetricGPU"), value: MetricFormat.percent(snapshot.gpuUsage),
|
||||
status: snapshot.gpuTemperature.map { "\(Int($0.rounded()))°C" },
|
||||
statusHelp: Text("gpu.temperatureHelp"),
|
||||
detail: snapshot.gpu?.coreCount.map { String(format: String(localized: "gpu.coreCountFormat"), $0) }) {
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.gpu),
|
||||
second: samples.map(\.gpuRenderer), third: samples.map(\.gpuTiler),
|
||||
color: Color("MetricGPU"), secondColor: Color("MetricCPU"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "gpu.renderer", thirdLabel: "gpu.tiler",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
if snapshot.gpuUsage == nil { Text("gpu.unavailable").foregroundStyle(.secondary) }
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1).padding(.vertical, 3)
|
||||
gpuActivity("gpu.rendererActivity", value: snapshot.gpu?.renderer, color: Color("MetricCPU"))
|
||||
gpuActivity("gpu.tilerActivity", value: snapshot.gpu?.tiler, color: Color("SeriesSystem"))
|
||||
Divider().padding(.vertical, 3)
|
||||
Spacer(minLength: 0)
|
||||
GPUStatisticsView(inUse: snapshot.gpu?.inUseMemory, allocated: snapshot.gpu?.allocatedMemory,
|
||||
average: summary.average, peak: summary.peak)
|
||||
Spacer(minLength: 0)
|
||||
if let fans = snapshot.fans, !fans.isEmpty {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 5) {
|
||||
ForEach(fans) { fan in
|
||||
FanSpeedIndicator(title: fans.count == 2 ? (fan.id == 0 ? "gpu.fanLeft" : "gpu.fanRight") : LocalizedStringKey("\(String(localized: "gpu.fan")) \(fan.id + 1)"), rpm: fan.rpm)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 7).padding(.vertical, 5)
|
||||
.background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func gpuActivity(_ title: LocalizedStringKey, value: Double?, color: Color) -> some View {
|
||||
HStack(spacing: 8) {
|
||||
Text(title).frame(width: 65, alignment: .leading)
|
||||
MetricProgressBar(value: value ?? 0, color: color).frame(height: 5)
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
|
||||
AnimatedMetricText(value: MetricFormat.percent(value)).frame(width: 30, alignment: .trailing)
|
||||
}.font(.system(size: 10)).help(Text("gpu.pipelineHelp"))
|
||||
}
|
||||
private var memoryCard: some View {
|
||||
ResourceCard(title: "metric.memory", symbol: "memorychip", color: Color("MemoryApplication"),
|
||||
value: snapshot.memory.map { String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824) } ?? "--") {
|
||||
PanelTrendChart(dates: samples.map(\.date),
|
||||
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
|
||||
second: samples.map(\.memoryApp), third: samples.map(\.memoryWired), fourth: samples.map(\.memoryCompressed),
|
||||
color: Color("MetricCPU"), secondColor: Color("MemoryApplication"),
|
||||
thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1),
|
||||
scaleLabel: MetricFormat.memory(snapshot.memory?.total), firstValueFormat: .memory, firstLabel: "gpu.totalUtilization",
|
||||
secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
if let memory = snapshot.memory {
|
||||
MemoryDetailsView(memory: memory)
|
||||
} else { Text("metric.waiting") }
|
||||
}
|
||||
}
|
||||
@ViewBuilder private func pressure(_ value: Int?) -> some View {
|
||||
switch value {
|
||||
case 1: Text("pressure.normal")
|
||||
case 2: Text("pressure.warning").foregroundStyle(.orange)
|
||||
case 4: Text("pressure.critical").foregroundStyle(.red)
|
||||
default: Text(verbatim: "--")
|
||||
}
|
||||
}
|
||||
private var networkCard: some View {
|
||||
ResourceCard(title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: "↓ " + MetricFormat.rate(total(\.download)), secondaryValue: "↑ " + MetricFormat.rate(total(\.upload)), valueColor: Color("MetricMemory"), secondaryValueColor: Color("SeriesUpload")) {
|
||||
PanelTrendChart(dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"), secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, plotHeight: 58, showsLegendValues: false).id(selectedInterface)
|
||||
Divider().padding(.vertical, 4)
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
networkTotal("network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }), symbol: "arrow.down", color: Color("MetricMemory"))
|
||||
Divider().frame(height: 32)
|
||||
networkTotal("network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }), symbol: "arrow.up", color: Color("SeriesUpload"))
|
||||
Divider().frame(height: 32)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("network.status").foregroundStyle(.secondary)
|
||||
Picker("panel.interface", selection: $selectedInterface) {
|
||||
Text("network.all").tag("")
|
||||
ForEach(snapshot.network ?? [], id: \.identity) { item in
|
||||
Text(verbatim: item.name).tag(item.identity)
|
||||
}
|
||||
}.labelsHidden().controlSize(.mini).fixedSize()
|
||||
}
|
||||
HStack(spacing: 4) {
|
||||
Circle().fill(networkStatusColor).frame(width: 5, height: 5)
|
||||
Text(networkStatusLabel)
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.65)
|
||||
Divider().padding(.vertical, 4)
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("network.addresses").fontWeight(.medium).foregroundStyle(.secondary)
|
||||
HStack(spacing: 8) {
|
||||
networkAddress("network.public", address: publicIPAddress)
|
||||
Divider().frame(height: 15)
|
||||
networkAddress("network.local", address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first)
|
||||
}
|
||||
}.font(.system(size: 10))
|
||||
.padding(.horizontal, 7).padding(.vertical, 5)
|
||||
.background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
.task(id: publicIPRoute) {
|
||||
publicIPAddress = nil
|
||||
guard snapshot.networkPath == .available else { return }
|
||||
let address = await PublicIPAddressService.shared.address(route: publicIPRoute)
|
||||
guard !Task.isCancelled else { return }
|
||||
publicIPAddress = address
|
||||
}
|
||||
}
|
||||
private var publicIPRoute: String {
|
||||
"\(snapshot.defaultNetworkInterface ?? ""):\(String(describing: snapshot.networkPath)):\(snapshot.network?.filter { $0.active }.map { $0.addresses.joined(separator: ",") }.joined(separator: ";") ?? "")"
|
||||
}
|
||||
private func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Text(verbatim: address ?? "--").monospacedDigit().textSelection(.enabled)
|
||||
Spacer(minLength: 0)
|
||||
if let address {
|
||||
Button {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(address, forType: .string)
|
||||
} label: { Image(systemName: "doc.on.doc") }
|
||||
.buttonStyle(.plain).accessibilityLabel(Text("panel.copy"))
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading).lineLimit(1).minimumScaleFactor(0.6)
|
||||
}
|
||||
private func networkTotal(_ title: LocalizedStringKey, value: String, symbol: String, color: Color) -> some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
AnimatedMetricText(value: value).fontWeight(.medium)
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
private var networkStatusLabel: LocalizedStringKey {
|
||||
switch snapshot.networkPath {
|
||||
case .available: "network.pathAvailable"
|
||||
case .unavailable: "network.pathUnavailable"
|
||||
case .requiresConnection: "network.pathRequiresConnection"
|
||||
case nil: "metric.waiting"
|
||||
}
|
||||
}
|
||||
private var networkStatusColor: Color {
|
||||
switch snapshot.networkPath {
|
||||
case .available: .green
|
||||
case .unavailable: .red
|
||||
case .requiresConnection: .orange
|
||||
case nil: .secondary
|
||||
}
|
||||
}
|
||||
private var addressInterface: NetworkInterfaceMetrics? {
|
||||
let name = selectedInterface.isEmpty ? snapshot.defaultNetworkInterface : network.first?.name
|
||||
return snapshot.network?.first { $0.name == name && $0.active }
|
||||
}
|
||||
private var networkIntervals: [TimeInterval] { selectedInterface.isEmpty ? chartIntervals : (metrics.history.interfaces[selectedInterface] ?? []).map(\.expectedInterval) }
|
||||
private var networkDates: [Date] { selectedInterface.isEmpty ? samples.map(\.date) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.date) }
|
||||
private var networkDownloads: [Double?] { selectedInterface.isEmpty ? samples.map(\.download) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.download) }
|
||||
private var networkUploads: [Double?] { selectedInterface.isEmpty ? samples.map(\.upload) : (metrics.history.interfaces[selectedInterface] ?? []).map(\.upload) }
|
||||
private var diskCard: some View {
|
||||
ResourceCard(title: "metric.disk", symbol: "internaldrive", color: Color("MetricDisk"), value: snapshot.disk.map { String(format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--") {
|
||||
|
||||
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, plotHeight: 48)
|
||||
Text("disk.physicalIO")
|
||||
.font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth) {
|
||||
showVolumes.toggle()
|
||||
}
|
||||
.popover(isPresented: $showVolumes) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("disk.homeVolume")
|
||||
Text("panel.smartScope").foregroundStyle(.secondary)
|
||||
Group {
|
||||
ForEach(snapshot.volumes ?? [], id: \.path) { volume in
|
||||
VStack(alignment: .leading) {
|
||||
Text(verbatim: volume.name).lineLimit(1).truncationMode(.middle)
|
||||
line("memory.available", "\(MetricFormat.bytes(volume.capacity.available)) / \(MetricFormat.bytes(volume.capacity.total))")
|
||||
}
|
||||
}
|
||||
Text("panel.apfsScope").font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
}
|
||||
}.padding(12).frame(width: 330)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private var batteryCard: some View {
|
||||
ResourceCard(title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"), value: MetricFormat.percent(snapshot.battery?.charge)) {
|
||||
if let battery = snapshot.battery {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map(\.battery),
|
||||
second: samples.map(\.batteryPower),
|
||||
color: Color("MetricBattery"),
|
||||
secondColor: Color("SeriesUser"),
|
||||
fixedScale: 1,
|
||||
secondSeriesUsesAutonomousScale: true,
|
||||
secondValueFormat: .watts,
|
||||
firstLabel: "metric.battery",
|
||||
secondLabel: batteryPowerLabel(battery),
|
||||
expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries,
|
||||
intervals: chartIntervals
|
||||
)
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1).padding(.vertical, 3)
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
VStack(spacing: 5) {
|
||||
line("battery.health", MetricFormat.percent(battery.health))
|
||||
HStack {
|
||||
Text("battery.powerSource").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
Text(battery.externalPower ? "battery.acPower" : "battery.batterySource")
|
||||
}
|
||||
}
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 32)
|
||||
VStack(spacing: 5) {
|
||||
line("battery.cycles", battery.cycles.map(String.init) ?? "--")
|
||||
HStack {
|
||||
Text("battery.timeEstimate").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
if battery.externalPower { Text("battery.timeNotApplicable") }
|
||||
else if let minutes = battery.minutesRemaining { AnimatedMetricText(value: "\(minutes) min") }
|
||||
else { Text("battery.timeUnknown") }
|
||||
}
|
||||
}
|
||||
}
|
||||
.font(.system(size: 10))
|
||||
.lineLimit(1).minimumScaleFactor(0.72)
|
||||
.frame(height: 32)
|
||||
Spacer(minLength: 0)
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1).padding(.vertical, 3)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("battery.highestEnergyProcess").fontWeight(.semibold)
|
||||
Spacer()
|
||||
Text("battery.cpuUsage").foregroundStyle(.secondary)
|
||||
}
|
||||
.font(.system(size: 10))
|
||||
let energyProcesses = snapshot.processes?.highestCPUProcesses(limit: 3) ?? []
|
||||
if energyProcesses.isEmpty {
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
} else {
|
||||
ForEach(energyProcesses) { process in
|
||||
EnergyProcessListRow(process: process)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reserve the header and all three rows before process sampling completes.
|
||||
.frame(height: 72, alignment: .top)
|
||||
.lineLimit(1)
|
||||
.help(Text("battery.energyProxyHelp"))
|
||||
|
||||
} else {
|
||||
Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
private var controls: some View {
|
||||
HStack(spacing: 8) {
|
||||
HStack(spacing: 2) {
|
||||
@@ -501,55 +183,6 @@ struct MenuPanelView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct EnergyProcessListRow: View {
|
||||
let process: ProcessMetrics
|
||||
@State private var icon: NSImage?
|
||||
|
||||
private var progress: Double {
|
||||
guard let value = process.cpu, value.isFinite else { return 0 }
|
||||
return min(max(value, 0), 1)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
Group {
|
||||
if let icon {
|
||||
Image(nsImage: icon).resizable().interpolation(.high)
|
||||
} else {
|
||||
Image(systemName: "app.dashed").resizable().scaledToFit().padding(2)
|
||||
}
|
||||
}
|
||||
.frame(width: 15, height: 15)
|
||||
.accessibilityHidden(true)
|
||||
Text(verbatim: process.name).lineLimit(1).truncationMode(.middle)
|
||||
.frame(width: 66, alignment: .leading)
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(.primary.opacity(0.07))
|
||||
.overlay(alignment: .leading) {
|
||||
Capsule().fill(Color("MetricCPU"))
|
||||
.frame(width: proxy.size.width * progress, height: 4)
|
||||
.clipped()
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.frame(height: 4)
|
||||
.animation(.easeInOut(duration: 0.35), value: process.cpu)
|
||||
AnimatedMetricText(value: process.cpu.map { String(format: "%.1f%%", $0 * 100) } ?? "--")
|
||||
.foregroundStyle(Color("MetricCPU"))
|
||||
.monospacedDigit().frame(width: 39, alignment: .trailing)
|
||||
}
|
||||
.font(.system(size: 10))
|
||||
.frame(height: 16)
|
||||
.task(id: process.id) {
|
||||
icon = NSRunningApplication(processIdentifier: process.id.pid)?.icon
|
||||
if icon == nil, let path = process.path {
|
||||
icon = NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private struct PanelControlButtonStyle: ButtonStyle {
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
PanelControlButtonBody(isPressed: configuration.isPressed) {
|
||||
|
||||
@@ -2,12 +2,29 @@ import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
nonisolated enum PanelLayout {
|
||||
static func resourceRowHeight(size: CGSize, coreRows: Int) -> CGFloat {
|
||||
let compact = min(239, max(224, size.height - 581))
|
||||
let thirdRowExpansion: CGFloat = coreRows >= 3 ? 26 : 0
|
||||
return min(265, compact + thirdRowExpansion)
|
||||
static let baseCardHeight: CGFloat = 280
|
||||
static func columns(width: CGFloat) -> Int { width >= 1160 ? 3 : width >= 900 ? 2 : 1 }
|
||||
static func cardWidth(size: CGSize) -> CGFloat {
|
||||
let count = columns(width: size.width)
|
||||
return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count))
|
||||
}
|
||||
/// Heights are assigned by physical row, including the battery/memory pair at two columns.
|
||||
static func rowHeights(columns: Int, coreRows: Int, fanCount: Int) -> [CGFloat] {
|
||||
let cpu = baseCardHeight + CGFloat(max(0, coreRows - 2)) * 26
|
||||
let gpu = baseCardHeight + CGFloat(max(0, (fanCount + 1) / 2 - 1)) * 26
|
||||
let heights = [cpu, gpu, baseCardHeight, baseCardHeight, baseCardHeight, baseCardHeight]
|
||||
let count = max(1, min(3, columns))
|
||||
return stride(from: 0, to: heights.count, by: count).map {
|
||||
heights[$0..<min($0 + count, heights.count)].max() ?? baseCardHeight
|
||||
}
|
||||
}
|
||||
static func resourceHeight(rows: [CGFloat]) -> CGFloat {
|
||||
rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8
|
||||
}
|
||||
static func needsResourceScroll(size: CGSize, rows: [CGFloat]) -> Bool {
|
||||
// Outer padding, toolbar budget, two gaps, and the minimum process area.
|
||||
resourceHeight(rows: rows) > size.height - 20 - 40 - 16 - 170
|
||||
}
|
||||
static func cardWidth(size: CGSize) -> CGFloat { max(0, (size.width - 36) / 3) }
|
||||
|
||||
static func contentSize(visible: CGRect, chrome: CGSize = .zero) -> CGSize {
|
||||
CGSize(width: max(1, min(1240, visible.width - 32 - max(0, chrome.width))),
|
||||
|
||||
@@ -69,8 +69,7 @@ struct ProcessTableView: View {
|
||||
}
|
||||
}
|
||||
.font(.system(size: 12)).padding(10)
|
||||
.modifier(PanelCardBackground(radius: 14))
|
||||
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(.primary.opacity(0.1)))
|
||||
.modifier(CardSurface())
|
||||
.onAppear { rebuild(retainOrder: false) }
|
||||
.onChange(of: snapshot?.date) { _, _ in rebuild(retainOrder: held && (byMemory ? rows.contains { $0.residentBytes != nil } : rows.contains { $0.cpu != nil })) }
|
||||
.onChange(of: search) { _, _ in rebuild(retainOrder: held) }
|
||||
@@ -92,7 +91,7 @@ struct ProcessTableView: View {
|
||||
}
|
||||
private var processTitle: some View {
|
||||
HStack(spacing: 8) {
|
||||
Label("panel.processes", systemImage: "list.bullet.rectangle").fontWeight(.semibold)
|
||||
Label("panel.processes", systemImage: "list.bullet.rectangle").font(PanelStyle.title)
|
||||
Text(verbatim: "\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)")
|
||||
.foregroundStyle(.secondary).help(Text("panel.coverage"))
|
||||
}
|
||||
|
||||
@@ -4,65 +4,40 @@ 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)
|
||||
CardSeparator()
|
||||
CardSectionHeader(title: "disk.distribution", valueLabel: "disk.utilization",
|
||||
value: MetricFormat.percent(disk?.usage), color: color)
|
||||
.help(Text("disk.capacityScope"))
|
||||
CapacityBar(values: [Double(disk.map { $0.total - min($0.total, $0.available) } ?? 0), Double(disk?.available ?? 0)],
|
||||
colors: [color, Color("MemoryAvailable")], total: Double(disk?.total ?? 1))
|
||||
HStack(spacing: 4) {
|
||||
CapacityField(title: "disk.used", value: MetricFormat.bytes(disk.map { $0.total - min($0.total, $0.available) }), color: color)
|
||||
CapacityField(title: "memory.available", value: MetricFormat.bytes(disk?.available), color: Color("MemoryAvailable"))
|
||||
}
|
||||
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()
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("disk.remainingLife").foregroundStyle(.secondary)
|
||||
CardField(title: "disk.remainingLife") {
|
||||
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)
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.powerOnHours") {
|
||||
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)
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.localVolumes") {
|
||||
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)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ struct PanelTrendChart: View {
|
||||
var expectedInterval: TimeInterval = 2
|
||||
var boundaryDates: Set<Date> = []
|
||||
var intervals: [TimeInterval] = []
|
||||
var plotHeight: CGFloat = 58
|
||||
var plotHeight: CGFloat = PanelStyle.plotHeight
|
||||
var showsLegendValues = true
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var retainedScale: Double = 1
|
||||
@@ -84,7 +84,7 @@ struct PanelTrendChart: View {
|
||||
if showsLegendValues {
|
||||
Text(verbatim: formatted(values.last ?? nil, format: format)).monospacedDigit()
|
||||
}
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.8)
|
||||
}.font(PanelStyle.legend).lineLimit(1).minimumScaleFactor(0.8)
|
||||
}
|
||||
|
||||
private func tooltipRow(_ label: LocalizedStringKey, values: [Double?], tint: Color, format: TrendValueFormat? = nil, index: Int) -> some View {
|
||||
@@ -181,7 +181,7 @@ struct PanelTrendChart: View {
|
||||
if let date = dates.first { Text(date, style: .time) }
|
||||
Spacer(minLength: 0)
|
||||
if let date = dates.last { Text(date, style: .time) }
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(height: 12)
|
||||
}.font(PanelStyle.legend).foregroundStyle(.secondary).frame(height: 12)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.onAppear {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Shared roles for the compact monitoring panel. Micro charts keep their own 8pt role.
|
||||
enum PanelStyle {
|
||||
static let title = Font.system(size: 13, weight: .semibold)
|
||||
static let section = Font.system(size: 11, weight: .semibold)
|
||||
static let label = Font.system(size: 10)
|
||||
static let value = Font.system(size: 10, weight: .medium)
|
||||
static let legend = Font.system(size: 9)
|
||||
static let padding: CGFloat = 10
|
||||
static let gap: CGFloat = 8
|
||||
static let titleHeight: CGFloat = 20
|
||||
static let plotHeight: CGFloat = 58
|
||||
}
|
||||
|
||||
struct CardSeparator: View {
|
||||
var body: some View {
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1)
|
||||
.padding(.vertical, 4)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardField<Content: View>: View {
|
||||
let title: LocalizedStringKey
|
||||
@ViewBuilder var content: () -> Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title)).frame(height: 14)
|
||||
content().font(PanelStyle.value).monospacedDigit().frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardSurface: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content.modifier(PanelCardBackground(radius: 10))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
||||
}
|
||||
}
|
||||
|
||||
struct CardInset: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content.padding(.horizontal, 8).padding(.vertical, 5)
|
||||
.background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
}
|
||||
|
||||
/// Segment widths are proportional to the supplied total, without minimum fills.
|
||||
struct CapacityBar: View {
|
||||
let values: [Double]
|
||||
let colors: [Color]
|
||||
let total: Double
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { bounds in
|
||||
HStack(spacing: 0) {
|
||||
ForEach(values.indices, id: \.self) { index in
|
||||
Rectangle().fill(colors.isEmpty ? Color.clear : colors[index % colors.count])
|
||||
.frame(width: bounds.size.width * min(1, max(0, values[index] / max(1, total))))
|
||||
}
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
||||
}
|
||||
.frame(height: 8)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
struct CapacityField: View {
|
||||
let title: LocalizedStringKey
|
||||
let value: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(color).frame(width: 4, height: 4)
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title))
|
||||
}.frame(height: 14)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardSectionHeader: View {
|
||||
let title: LocalizedStringKey
|
||||
let valueLabel: LocalizedStringKey
|
||||
let value: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(title).font(PanelStyle.section)
|
||||
Spacer(minLength: 4)
|
||||
Text(valueLabel).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).foregroundStyle(color)
|
||||
}.frame(height: 16)
|
||||
}
|
||||
}
|
||||
@@ -16,48 +16,55 @@ struct ResourceCard<Content: View>: View {
|
||||
@ViewBuilder var content: () -> Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
Label { Text(title).foregroundStyle(statusWarning ? .red : .primary) } icon: {
|
||||
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
|
||||
}.font(.system(size: 13, weight: .semibold)).fixedSize()
|
||||
if let status {
|
||||
Text(verbatim: status)
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
.foregroundStyle(statusWarning ? .red : color)
|
||||
.padding(.horizontal, 6).padding(.vertical, 2)
|
||||
.background((statusWarning ? Color.red : color).opacity(0.14), in: Capsule())
|
||||
.help(statusHelp ?? Text(verbatim: status))
|
||||
if let warningText {
|
||||
warningText
|
||||
.font(.system(size: 10)).foregroundStyle(.red).lineLimit(1).minimumScaleFactor(0.7)
|
||||
}
|
||||
}
|
||||
if let detail {
|
||||
Text(verbatim: detail)
|
||||
.font(.system(size: 9, weight: .medium)).foregroundStyle(.secondary)
|
||||
.padding(.horizontal, 5).padding(.vertical, 2)
|
||||
.background(.primary.opacity(0.06), in: Capsule())
|
||||
.lineLimit(1).minimumScaleFactor(0.7)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
GeometryReader { bounds in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
AnimatedMetricText(value: value)
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
.foregroundStyle(valueColor ?? color)
|
||||
if let secondaryValue {
|
||||
AnimatedMetricText(value: secondaryValue).font(.system(size: 13, weight: .semibold))
|
||||
.foregroundStyle(secondaryValueColor ?? color)
|
||||
Label {
|
||||
Text(title).foregroundStyle(statusWarning ? .red : .primary)
|
||||
} icon: {
|
||||
Image(systemName: symbol).frame(width: 16, height: 16).foregroundStyle(statusWarning ? .red : color)
|
||||
}.font(PanelStyle.title).fixedSize()
|
||||
if let status {
|
||||
Text(verbatim: status)
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
.foregroundStyle(statusWarning ? .red : color)
|
||||
.padding(.horizontal, 6).frame(height: 16)
|
||||
.background((statusWarning ? Color.red : color).opacity(0.14), in: Capsule())
|
||||
.help(statusHelp ?? Text(verbatim: status))
|
||||
if let warningText {
|
||||
warningText
|
||||
.font(.system(size: 10)).foregroundStyle(.red).lineLimit(1)
|
||||
}
|
||||
}
|
||||
}.foregroundStyle(color).lineLimit(1).minimumScaleFactor(0.65)
|
||||
if let detail {
|
||||
Text(verbatim: detail)
|
||||
.font(.system(size: 10, weight: .medium)).foregroundStyle(.secondary)
|
||||
.padding(.horizontal, 6).frame(height: 16)
|
||||
.background(.primary.opacity(0.06), in: Capsule())
|
||||
.lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
AnimatedMetricText(value: value)
|
||||
.font(PanelStyle.title)
|
||||
.foregroundStyle(valueColor ?? color)
|
||||
if let secondaryValue {
|
||||
AnimatedMetricText(value: secondaryValue).font(PanelStyle.title)
|
||||
.foregroundStyle(secondaryValueColor ?? color)
|
||||
}
|
||||
}.foregroundStyle(color).lineLimit(1)
|
||||
}
|
||||
.frame(height: PanelStyle.titleHeight)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
content()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
content()
|
||||
.font(PanelStyle.label)
|
||||
.padding(PanelStyle.padding)
|
||||
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
|
||||
}
|
||||
.font(.system(size: 11))
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.modifier(PanelCardBackground(radius: 10))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
||||
.modifier(CardSurface())
|
||||
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
|
||||
GeometryReader { proxy in
|
||||
if let tooltip {
|
||||
|
||||
Reference in New Issue
Block a user