refactor(menubar): 精简内存卡片并对齐双列底部

This commit is contained in:
2026-11-09 00:05:25 +08:00
parent 28112bcf2e
commit 1afe82b233
15 changed files with 119 additions and 40 deletions
@@ -0,0 +1,27 @@
import SwiftUI
/// Presentation only: reuse the current snapshot without additional sampling on hover.
struct MemoryHeaderInfo {
let memory: MemoryMetrics?
let locale: Locale
var bundle: Bundle = .main
private var pressure: (key: String?, color: Color) {
switch memory?.pressure {
case 1: ("pressure.normal", Color("MetricCPU"))
case 2: ("pressure.warning", .orange)
case 4: ("pressure.critical", .red)
default: (nil, .secondary)
}
}
var title: String { pressure.key.map(localized) ?? "--" }
var color: Color { pressure.color }
var help: String {
"\(localized("memory.pressure")): \(title)\n"
+ "\(localized("memory.cached")): \(MetricFormat.memory(memory?.cached))\n"
+ "\(localized("memory.swap")): \(MetricFormat.memory(memory?.swapUsed))"
}
private func localized(_ key: String) -> String { AppLocalization.string(key, locale: locale, bundle: bundle) }
}