feat(cpu): 图形化展示负载并平滑更新核心占用
This commit is contained in:
@@ -12,6 +12,7 @@ struct MenuPanelView: View {
|
||||
@State private var selectedInterface = ""
|
||||
@State private var showAddresses = false
|
||||
@State private var showVolumes = false
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
|
||||
private var snapshot: MetricsSnapshot { metrics.snapshot }
|
||||
private var samples: [TrendSample] { metrics.history.samples }
|
||||
@@ -144,6 +145,7 @@ struct MenuPanelView: View {
|
||||
HStack(spacing: 3) {
|
||||
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
|
||||
MetricProgressBar(value: value, color: coreColor(kind)).frame(height: 7)
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
|
||||
}.help((kind.map { coreLabel($0) + Text(verbatim: " · ") } ?? Text("cpu.core")) + Text(verbatim: "\(index + 1): \(MetricFormat.percent(value))"))
|
||||
.accessibilityLabel(kind.map { coreLabel($0) } ?? Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
}
|
||||
@@ -151,7 +153,24 @@ struct MenuPanelView: View {
|
||||
|
||||
} else { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
Spacer(minLength: 0)
|
||||
HStack { line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / ")).help(Text("cpu.load.help", tableName: "CPUDetails")); Spacer(minLength: 8); Text("panel.uptime").foregroundStyle(.secondary); AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600)) }
|
||||
HStack(spacing: 5) {
|
||||
HStack(spacing: 5) {
|
||||
Text("cpu.load.oneMinute", tableName: "CPUDetails").foregroundStyle(.secondary)
|
||||
if let load = snapshot.load.first, load.isFinite, load >= 0, let count = snapshot.cpu?.cores.count, count > 0 {
|
||||
MetricProgressBar(value: load / Double(count), color: Color("MetricCPU"))
|
||||
.frame(minWidth: 20, maxWidth: .infinity).frame(height: 7)
|
||||
.accessibilityHidden(true)
|
||||
AnimatedMetricText(value: "\(MetricFormat.decimal(load)) / \(count)")
|
||||
} else {
|
||||
Spacer(minLength: 20)
|
||||
Text(verbatim: "--")
|
||||
}
|
||||
}
|
||||
.help(Text("cpu.load.help", tableName: "CPUDetails"))
|
||||
Spacer(minLength: 8)
|
||||
Text("panel.uptime").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600))
|
||||
}
|
||||
.lineLimit(1).minimumScaleFactor(0.7)
|
||||
|
||||
}
|
||||
|
||||
@@ -76,19 +76,42 @@
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Average system load over the last 1, 5 and 15 minutes."
|
||||
"value": "Average system load over the last minute. The bar is full at the number of logical CPU cores; load can exceed that number."
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "最近 1、5、15 分钟的系统平均负载。"
|
||||
"value": "最近 1 分钟的系统平均负载。进度条满格对应逻辑核心数,负载可能超过该数值。"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "最近 1、5、15 分鐘的系統平均負載。"
|
||||
"value": "最近 1 分鐘的系統平均負載。進度條滿格對應邏輯核心數,負載可能超過該數值。"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.load.oneMinute": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Load · 1 min"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "负载 · 1 分钟"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "負載 · 1 分鐘"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ struct MetricProgressBar: View {
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule().fill(color.opacity(0.15))
|
||||
if fraction > 0 {
|
||||
Capsule().fill(color).frame(width: proxy.size.width * fraction)
|
||||
}
|
||||
Capsule().fill(color).frame(width: proxy.size.width * fraction)
|
||||
}
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
.clipShape(Capsule())
|
||||
|
||||
Reference in New Issue
Block a user