feat(menubar): 完善首排监控卡片与温度风扇采样
补充 GPU 渲染分块、内存与利用率统计,增加只读 SMC 温度及风扇信息和旋转动效。完善电池功率与耗电进程列表,统一首排布局并固定异步加载区域高度。同步验证用例、架构说明和 GPU 能力调研工具。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Approximate visual speed tiers; rotation does not attempt to reproduce physical RPM.
|
||||
nonisolated struct FanRotation {
|
||||
private(set) var phase: Double = 0
|
||||
private(set) var speed: Double = 0
|
||||
private var reference: TimeInterval = 0
|
||||
|
||||
static func speed(rpm: Double?, reducedMotion: Bool) -> Double {
|
||||
guard !reducedMotion, let rpm, rpm.isFinite, rpm > 0 else { return 0 }
|
||||
switch rpm {
|
||||
case ..<2000: return 90
|
||||
case ..<4000: return 180
|
||||
case ..<6000: return 300
|
||||
default: return 450
|
||||
}
|
||||
}
|
||||
|
||||
func angle(at time: TimeInterval) -> Double {
|
||||
(phase + max(0, time - reference) * speed).truncatingRemainder(dividingBy: 360)
|
||||
}
|
||||
|
||||
mutating func update(rpm: Double?, reducedMotion: Bool, at time: TimeInterval) {
|
||||
phase = angle(at: time)
|
||||
reference = time
|
||||
speed = Self.speed(rpm: rpm, reducedMotion: reducedMotion)
|
||||
}
|
||||
}
|
||||
|
||||
struct FanSpeedIndicator: View {
|
||||
let title: LocalizedStringKey
|
||||
let rpm: Double?
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var rotation = FanRotation()
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
TimelineView(.animation(minimumInterval: 1.0 / 30, paused: rotation.speed == 0)) { context in
|
||||
Image(systemName: "fanblades.fill")
|
||||
.rotationEffect(.degrees(rotation.angle(at: context.date.timeIntervalSinceReferenceDate)))
|
||||
.foregroundStyle(.secondary)
|
||||
}.frame(width: 14, height: 14).accessibilityHidden(true)
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 2)
|
||||
AnimatedMetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM")
|
||||
.monospacedDigit().fontWeight(.medium)
|
||||
}
|
||||
.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
.onAppear { update() }
|
||||
.onChange(of: rpm) { _, _ in update() }
|
||||
.onChange(of: reduceMotion) { _, _ in update() }
|
||||
}
|
||||
|
||||
private func update() {
|
||||
rotation.update(rpm: rpm, reducedMotion: reduceMotion, at: Date.timeIntervalSinceReferenceDate)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import SwiftUI
|
||||
|
||||
/// A bounded percentage gauge; missing data keeps an empty track and an explicit -- label.
|
||||
struct MetricRingGauge: View {
|
||||
let title: LocalizedStringKey
|
||||
let value: Double?
|
||||
let color: Color
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
|
||||
private var fraction: Double { value.flatMap { $0.isFinite ? min(1, max(0, $0)) : nil } ?? 0 }
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 3) {
|
||||
ZStack {
|
||||
Circle().stroke(color.opacity(0.17), lineWidth: 3)
|
||||
Circle().trim(from: 0, to: fraction)
|
||||
.stroke(color, style: StrokeStyle(lineWidth: 3, lineCap: .round))
|
||||
.rotationEffect(.degrees(-90))
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: fraction)
|
||||
AnimatedMetricText(value: MetricFormat.percent(value)).font(.system(size: 8, weight: .semibold))
|
||||
.lineLimit(1).minimumScaleFactor(0.6).frame(width: 18, height: 12)
|
||||
}.padding(2).frame(width: 28, height: 28).accessibilityHidden(true)
|
||||
Text(title).font(.system(size: 8)).foregroundStyle(.secondary)
|
||||
.lineLimit(1).minimumScaleFactor(0.7)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(Text(title))
|
||||
.accessibilityValue(Text(verbatim: MetricFormat.percent(value)))
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,40 @@ struct ResourceCard<Content: View>: View {
|
||||
let color: Color
|
||||
let value: String
|
||||
var secondaryValue: String? = nil
|
||||
var status: String? = nil
|
||||
var statusWarning = false
|
||||
var statusHelp: Text? = nil
|
||||
var warningText: Text? = nil
|
||||
var detail: String? = nil
|
||||
@ViewBuilder var content: () -> Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||
Label { Text(title).foregroundStyle(.primary) } icon: {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
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)
|
||||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
AnimatedMetricText(value: value)
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
if let secondaryValue {
|
||||
|
||||
Reference in New Issue
Block a user