feat(panel): 调整资源卡片读数布局并保留趋势平移

逐核显示 CPU 占用,在 GPU 标题展示核数并补充分项读数。无电池设备显示整机功率。

存储与网络将曲线排在详情下方,CPU、GPU、内存和电池保留整卡趋势。数值直接刷新,曲线随采样平滑平移。顶栏展示版本号,底栏调整开机时间和刷新间隔。
This commit is contained in:
2026-11-15 22:03:46 +08:00
parent c886c4227d
commit 6300db3d15
27 changed files with 427 additions and 250 deletions
+15 -15
View File
@@ -11,7 +11,7 @@ import SwiftUI
styleMask: [.borderless], backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
window.level = .floating
let host = NSHostingView(rootView: Example(value: "128", probe: probe))
let host = NSHostingView(rootView: Example(value: "12.8 W", probe: probe))
host.sizingOptions = []
window.contentView = host
window.orderFrontRegardless()
@@ -22,18 +22,18 @@ import SwiftUI
precondition(probe.appearances == 1 && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
precondition(redPixels(before) > 30, "Foreground style must cross the native boundary")
let originalLifetime = ObjectIdentifier(probe.lifetime!)
host.rootView = Example(value: "345", probe: probe)
try? await Task.sleep(for: .milliseconds(140))
let settled = bitmap(host)
try? await Task.sleep(for: .milliseconds(600))
let after = bitmap(host)
precondition(before.bitmapData != nil && after.bitmapData != nil)
precondition(pixels(before) != pixels(after), "Changed values must reach the retained child host")
precondition(pixels(settled) == pixels(after),
"A sample must settle immediately without numeric rolling or a later animation frame")
host.rootView = Example(value: "12.9 W", probe: probe)
try? await Task.sleep(for: .milliseconds(40))
let updated = pixels(bitmap(host))
precondition(updated != pixels(before), "The next render must display the new reading")
try? await Task.sleep(for: .milliseconds(500))
precondition(updated == pixels(bitmap(host)), "Updated digits must be stationary")
host.rootView = Example(value: "12.8 W", probe: probe)
try? await Task.sleep(for: .milliseconds(40))
precondition(pixels(bitmap(host)) == pixels(before), "A decrease must restore the original digits immediately")
precondition(probe.appearances == 1 && probe.lifetime.map(ObjectIdentifier.init) == originalLifetime,
"Sampling must update mounted content, not remount it")
host.rootView = Example(value: "345", probe: probe, locale: "zh_CN")
host.rootView = Example(value: "12.9 W", probe: probe, locale: "zh_CN")
try? await Task.sleep(for: .milliseconds(100))
precondition(probe.locale == "zh_CN")
window.setContentSize(NSSize(width: 360, height: 100))
@@ -44,7 +44,7 @@ import SwiftUI
}
let child = childHost(host)
precondition(child?.bounds.size == host.bounds.size, "The parent must remain the sole frame owner")
host.rootView = Example(value: "345", probe: probe, visible: false)
host.rootView = Example(value: "12.9 W", probe: probe, visible: false)
try? await Task.sleep(for: .milliseconds(150))
precondition(probe.disappearances == 1)
let releaseDeadline = ContinuousClock.now.advanced(by: .seconds(1))
@@ -55,7 +55,7 @@ import SwiftUI
window.orderOut(nil)
window.contentView = nil
window.close()
print("PASS: static card host preserves immediate stable text, inherited font/style/locale, child state, resize and unmount")
print("PASS: card host displays stationary updated digits and preserves inherited font/style/locale, child state, resize and unmount")
fflush(stdout)
NSApp.terminate(nil)
}
@@ -118,12 +118,12 @@ import SwiftUI
}
return data
}
private static func redPixels(_ bitmap: NSBitmapImageRep) -> Int {
private static func redPixels(_ bitmap: NSBitmapImageRep, contrast: CGFloat = 0.2) -> Int {
var count = 0
for x in 0..<bitmap.pixelsWide {
for y in 0..<bitmap.pixelsHigh {
if let color = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB),
color.redComponent > color.greenComponent + 0.2 && color.redComponent > color.blueComponent + 0.2 {
(color.redComponent - max(color.greenComponent, color.blueComponent)) * color.alphaComponent > contrast {
count += 1
}
}