接入 Mach CPU 差分、内存与负载采样、暂停恢复及按需诊断,合并菜单栏单一原生标题的显示修复。 保留核心检查和本机交互验收记录;长期资源预算仍待验收。
31 lines
893 B
Swift
31 lines
893 B
Swift
import SwiftUI
|
|
|
|
struct MenuBarLabel: View {
|
|
let snapshot: MetricsSnapshot
|
|
|
|
var body: some View {
|
|
// Use one native image/title label: the previous multi-view HStack showed
|
|
// only its first image and percentage in the user-verified menu bar.
|
|
Label {
|
|
Text(verbatim: title)
|
|
.monospacedDigit()
|
|
} icon: {
|
|
Image(systemName: "gauge")
|
|
}
|
|
.labelStyle(.titleAndIcon)
|
|
}
|
|
|
|
private var title: String {
|
|
var items = ["CPU \(percent(snapshot.cpu?.usage))"]
|
|
if let gpu = snapshot.gpuUsage {
|
|
items.append("GPU \(percent(gpu))")
|
|
}
|
|
items.append("MEM \(percent(snapshot.memory?.usage))")
|
|
return items.joined(separator: " · ")
|
|
}
|
|
|
|
private func percent(_ value: Double?) -> String {
|
|
value.map { "\(Int(($0 * 100).rounded()))%" } ?? "--"
|
|
}
|
|
}
|