refactor(menubar): 将进程路径移至末列
This commit is contained in:
@@ -10,9 +10,10 @@ import Observation
|
||||
var insideDelegate = false
|
||||
var exits = 0
|
||||
init() {
|
||||
rows = (0..<500).map { index in
|
||||
ProcessMetrics(id: ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0),
|
||||
name: "worker-\(index)", path: nil, cpu: Double(index) / 100,
|
||||
rows = (0..<500).map { index -> ProcessMetrics in
|
||||
let path: String? = index == 0 ? "/test/worker-0" : nil
|
||||
return ProcessMetrics(id: ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0),
|
||||
name: "worker-\(index)", path: path, cpu: Double(index) / 100,
|
||||
footprintBytes: 10_000_000, threads: 2, restricted: true)
|
||||
}
|
||||
}
|
||||
@@ -62,9 +63,20 @@ private struct Host: View {
|
||||
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.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 memoryCell = table.view(atColumn: 4, row: 0, makeIfNecessary: true) as! NSTableCellView
|
||||
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]
|
||||
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 memoryColumn = table.tableColumns.firstIndex { $0.identifier.rawValue == "memory" }!
|
||||
let memoryCell = table.view(atColumn: memoryColumn, row: 0, makeIfNecessary: true) as! NSTableCellView
|
||||
precondition(memoryCell.textField?.stringValue == "9.5 MB", "Memory column must match Activity Monitor binary MB display")
|
||||
let powerColumn = table.tableColumns.firstIndex { $0.identifier.rawValue == "power" }!
|
||||
let emptyPower = table.view(atColumn: powerColumn, row: 0, makeIfNecessary: true) as! NSTableCellView
|
||||
|
||||
Reference in New Issue
Block a user