fix(ui): 修正风扇转轴与速率图并精简进程表

This commit is contained in:
2026-11-15 19:21:18 +08:00
parent 99e558625b
commit 60c146f8b7
21 changed files with 303 additions and 107 deletions
+22 -7
View File
@@ -10,25 +10,40 @@ import SwiftUI
let rotor = FanRotor.RotorView(); rotor.frame = NSRect(x: 4, y: 4, width: 20, height: 20)
window.contentView!.addSubview(rotor); window.orderFrontRegardless()
try? await Task.sleep(for: .milliseconds(100))
for size: CGFloat in [11,20,32] {
rotor.setFrameSize(NSSize(width: size, height: size)); rotor.layoutSubtreeIfNeeded()
precondition(rotor.rotorLayer.anchorPoint == CGPoint(x: 0.5, y: 0.5))
precondition(rotor.rotorLayer.contents != nil)
precondition(CATransform3DIsIdentity(rotor.layer!.transform), "AppKit's host layer must never rotate")
CATransaction.begin(); CATransaction.setDisableActions(true)
for degrees in [0.0,45,90,180,270] {
rotor.rotorLayer.transform = CATransform3DMakeRotation(degrees * .pi / 180, 0, 0, 1)
let center = rotor.rotorLayer.convert(CGPoint(x: size / 2, y: size / 2), to: rotor.layer!)
precondition(abs(center.x - rotor.bounds.midX) < 1e-9 && abs(center.y - rotor.bounds.midY) < 1e-9,
"The icon center must not orbit at any angle or size")
}
rotor.rotorLayer.transform = CATransform3DIdentity
CATransaction.commit()
}
for (rpm, duration) in [(1000.0,4.0),(2000,2),(4000,1.2),(6000,0.8)] {
rotor.configure(rpm: rpm, active: true, reducedMotion: false)
precondition(abs(rotor.layer!.animation(forKey: FanRotor.RotorView.animationKey)!.duration - duration) < 1e-9)
precondition(abs(rotor.rotorLayer.animation(forKey: FanRotor.RotorView.animationKey)!.duration - duration) < 1e-9)
}
for rpm: Double? in [0,nil,.nan,-1] {
rotor.configure(rpm: rpm, active: true, reducedMotion: false)
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false)
}
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
precondition(rotor.layer!.animationKeys()?.isEmpty == false)
precondition(rotor.rotorLayer.animationKeys()?.isEmpty == false)
rotor.configure(rpm: 3000, active: false, reducedMotion: false)
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false)
rotor.configure(rpm: 3000, active: true, reducedMotion: true)
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false)
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
rotor.removeFromSuperview()
precondition(rotor.layer!.animationKeys()?.isEmpty != false, "Detached fans must stop rotating")
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false, "Detached fans must stop rotating")
window.orderOut(nil); window.close()
print("PASS: native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop")
print("PASS: centered child-layer rotation at multiple angles/sizes, native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop")
NSApp.terminate(nil)
}
NSApp.run()
+9
View File
@@ -4,6 +4,15 @@ import Foundation
precondition(MetricFormat.memory(51_539_607_552) == "48.0 GiB")
precondition(MetricFormat.memory(0) == "0 B")
precondition(MetricFormat.memory(nil) == "--")
for m in [
MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30, compressed: 1 << 30, swapUsed: 8 << 30, pressure: 1, cached: 17 << 30),
MemoryMetrics(total: 32 << 30, used: 20 << 30, wired: 2 << 30, compressed: 13 << 30, swapUsed: 4 << 30, pressure: 2, cached: 8 << 30),
MemoryMetrics(total: 16 << 30, used: 0, wired: 0, compressed: 0, swapUsed: 0, pressure: 1, cached: 12 << 30)
] {
precondition(m.app + m.wired + m.compressed == m.used)
precondition(m.app + m.wired + m.compressed + m.available == m.total)
precondition(m.available == m.total - m.used, "Reclaimable cache and disk swap must not be added again")
}
guard let m = MemoryMonitor.sample() else { fatalError("No sample") }
precondition(m.app + m.wired + m.compressed + m.available == m.total)
var snapshot = MetricsSnapshot()
+32 -1
View File
@@ -129,10 +129,41 @@ import QuartzCore
plot.configure(stack)
precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0,
"Every stack band must respect the same real sampling break")
// Rate panels use a common zero axis, not a percent scale at the card top.
var rates = NativePanelCurve.Input(frame: .init(dates: dates,
series: [Array(repeating: 0.8, count: 4), Array(repeating: 0.4, count: 4)],
intervals: [2,2,2,2], boundaryDates: []), colors: [.red,.blue], scales: [1], maximumGap: 5,
filledSeriesCount: 2, projection: .split(upwardSeries: 0))
plot.configure(rates)
@MainActor func areaBox(_ index: Int) -> CGRect {
(plot.curves.sublayers![index].sublayers![0] as! CAShapeLayer).path!.boundingBoxOfPath
}
precondition(abs(areaBox(0).minY - 21.6) < 1e-9 && abs(areaBox(0).maxY - 36) < 1e-9)
precondition(abs(areaBox(1).minY - 36) < 1e-9 && abs(areaBox(1).maxY - 43.2) < 1e-9)
precondition(!plot.baseline.isHidden && abs(plot.baseline.path!.boundingBoxOfPath.midY - 36) < 1e-9)
precondition(redPixels(bitmap(plot)) > 10)
let rateBuilds = plot.pathBuildCount
rates.hoveredIndex = 1; plot.configure(rates)
precondition(abs((plot.layer!.sublayers!.last as! CAShapeLayer).path!.boundingBoxOfPath.midY - 43.2) < 1e-9)
precondition(plot.pathBuildCount == rateBuilds)
rates.projection = .split(upwardSeries: 1); plot.configure(rates)
precondition(abs(areaBox(0).maxY - 50.4) < 1e-9 && abs(areaBox(1).minY - 28.8) < 1e-9,
"Network download must go down and upload up without negating raw rates")
precondition(plot.pathBuildCount == rateBuilds + 1)
rates = .init(frame: .init(dates: dates,
series: [Array(repeating: 0.8, count: 4), Array(repeating: 0.4, count: 4)],
intervals: [2,2,2,2], boundaryDates: [dates[2]]), colors: [.red,.blue], scales: [1], maximumGap: 5,
filledSeriesCount: 2, projection: .split(upwardSeries: 0))
plot.configure(rates)
precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0)
for series in 0...1 {
precondition(PanelCurveProjection.split(upwardSeries: 0).y(value: 0, scale: 10, series: series, height: 176) == 105.6)
}
precondition(abs(PanelCurveProjection.split(upwardSeries: 0).y(value: 10, scale: 10, series: 0, height: 176) - 52.8) < 1e-9)
assertStatic(plot.layer!)
plot.removeFromSuperview()
window.orderOut(nil); window.close()
print("PASS: stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
print("PASS: bidirectional rate areas/zero axis/direction/hover/gaps, stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
+24 -10
View File
@@ -62,18 +62,32 @@ private struct Host: View {
let coordinator = table.delegate as! NativeProcessTable.Coordinator
let probe = DelegateProbe(state, coordinator)
table.delegate = probe
precondition(table.numberOfRows == 500 && table.tableColumns.count == 7)
precondition(table.tableColumns.map(\.identifier.rawValue) == ["pid", "name", "cpu", "memory", "power", "threads", "path"],
"The path column must follow all process metrics")
precondition(table.numberOfRows == 500 && table.tableColumns.count == 6)
precondition(table.tableColumns.map(\.identifier.rawValue) == ["pid", "name", "cpu", "memory", "power", "threads"],
"Only the six metric columns must be visible")
precondition(table.frame.width >= table.enclosingScrollView!.contentSize.width - 1, "Native table must fill its viewport")
precondition(coordinator.createdCells > 0 && coordinator.createdCells < 200, "Rows must be virtualized")
let pathCell = table.view(atColumn: table.tableColumns.count - 1, row: 0, makeIfNecessary: true) as! NSTableCellView
precondition(pathCell.textField?.stringValue == "/test/worker-0")
let copyPath = coordinator.menu(row: 0)!.items[2]
let copyMenu = coordinator.menu(row: 0)!, copyPath = copyMenu.items[2]
precondition(copyPath.isEnabled && copyPath.representedObject as? String == "/test/worker-0")
for ascending in [false, true] {
table.sortDescriptors = [NSSortDescriptor(key: "path", ascending: ascending)]
await until { state.sorting == [ProcessSort(key: .path, order: ascending ? .forward : .reverse)] }
let savedPasteboard = NSPasteboard.general.pasteboardItems?.map { item in
item.types.compactMap { type in item.data(forType: type).map { (type, $0) } }
} ?? []
copyMenu.performActionForItem(at: 2)
precondition(NSPasteboard.general.string(forType: .string) == "/test/worker-0",
"Hiding the path column must preserve the real Copy Path action")
NSPasteboard.general.clearContents()
let restored = savedPasteboard.map { values in
let item = NSPasteboardItem(); for (type, data) in values { item.setData(data, forType: type) }; return item
}
NSPasteboard.general.writeObjects(restored)
for width: CGFloat in [900,628,340] {
window.setContentSize(CGSize(width: width, height: 260))
try? await Task.sleep(for: .milliseconds(100)); host.layoutSubtreeIfNeeded()
precondition(abs(host.bounds.width - width) < 1)
let scroll = table.enclosingScrollView!
precondition(!scroll.hasHorizontalScroller)
precondition(table.rect(ofColumn: 5).maxX <= scroll.contentView.bounds.width + 1,
"All six columns must fit the viewport without horizontal scrolling: \(width), \(table.rect(ofColumn: 5)), \(scroll.contentView.bounds)")
}
let memoryColumn = table.tableColumns.firstIndex { $0.identifier.rawValue == "memory" }!
let memoryCell = table.view(atColumn: memoryColumn, row: 0, makeIfNecessary: true) as! NSTableCellView
@@ -124,7 +138,7 @@ private struct Host: View {
window.sendEvent(escape)
await until { state.exits == 1 }
window.orderOut(nil); window.close()
print("PASS: real native table virtualization/reuse, deferred delegate writes, identity selection, sorting, copy menu, missing paths, removal, locale and in-window Esc event routing")
print("PASS: six columns fit narrow/regular viewports, real hidden-path copy, native table virtualization/reuse, deferred delegate writes, identity selection, sorting, copy menu, missing paths, removal, locale and in-window Esc event routing")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
+4 -3
View File
@@ -1,7 +1,7 @@
import AppKit
import SwiftUI
/// Verify the production section fills its assigned row even when the scope note wraps.
/// Verify the production section fills its assigned row after removing the scope row.
@main struct ProcessSectionChecks {
@MainActor static func main() {
_ = NSApplication.shared; NSApp.setActivationPolicy(.accessory)
@@ -26,16 +26,17 @@ import SwiftUI
try? await Task.sleep(for: .milliseconds(100)); host.layoutSubtreeIfNeeded()
let scrolls = descendants(host).compactMap { $0 as? NSScrollView }.filter { $0.documentView is NSTableView }
precondition(scrolls.count == 1)
precondition(!scrolls[0].hasHorizontalScroller)
let scroll = scrolls[0], rect = scroll.convert(scroll.bounds, to: host)
let topRect = host.isFlipped ? rect : CGRect(x: rect.minX, y: host.bounds.height - rect.maxY, width: rect.width, height: rect.height)
precondition(abs(topRect.maxY - 166) < 1 && topRect.height > 75,
precondition(abs(topRect.maxY - 166) < 1 && topRect.height > 110,
"The native table must fill the equal-height row down to its 10pt inset: \(language), \(width), \(topRect)")
precondition(abs(topRect.minX - 10) < 1 && abs(topRect.maxX - (width - 10)) < 1)
}
}
}
host.rootView = AnyView(EmptyView()); window.orderOut(nil); window.close()
print("PASS: production process section at 176pt, wrapped scope notes, full remaining table height, two widths, three languages and light/dark")
print("PASS: production process section at 176pt, no scope row or horizontal scrollbar, full remaining table height, two widths, three languages and light/dark")
NSApp.terminate(nil)
}
NSApp.run()
+1 -22
View File
@@ -39,32 +39,11 @@ import SwiftUI
}
}
}
// Render the production memory distribution: real UInt64 capacities must form visible segments.
window.appearance = NSAppearance(named: .aqua)
let memory = MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30,
compressed: 1 << 30, swapUsed: 0, pressure: 1)
host.rootView = AnyView(MemoryDetailsView(memory: memory)
.frame(width: 185, height: 44, alignment: .topLeading)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.environment(\.colorScheme, .light))
try? await Task.sleep(for: .milliseconds(120))
host.layoutSubtreeIfNeeded()
let bitmap = host.bitmapImageRepForCachingDisplay(in: host.bounds)!
host.cacheDisplay(in: host.bounds, to: bitmap)
var colored = 0
for y in 0..<bitmap.pixelsHigh {
for x in 0..<bitmap.pixelsWide {
guard let c = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB) else { continue }
let components = [c.redComponent, c.greenComponent, c.blueComponent]
if components.max()! - components.min()! > 0.2 && c.alphaComponent > 0.2 { colored += 1 }
}
}
precondition(colored > 200, "Memory classification capacities must produce a visible proportion bar")
host.rootView = AnyView(EmptyView())
try? await Task.sleep(for: .milliseconds(100))
precondition(descendants(host).allSatisfy { !($0 is NativePanelCurve.PlotView) })
window.orderOut(nil); window.contentView = nil; window.close()
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, memory distribution pixels and unmount")
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, unmount")
NSApp.terminate(nil)
}
NSApp.run()