fix(design): 按概念图重排面板层级并验证真实组件
This commit is contained in:
@@ -3,6 +3,8 @@ import AppKit
|
||||
|
||||
struct ProcessTableView: View {
|
||||
let snapshot: ProcessSnapshot?
|
||||
var wide: Bool = true
|
||||
var logicalCPUCount: Int = 1
|
||||
@State private var search = ""
|
||||
@State private var byMemory = false
|
||||
@State private var hovering = false
|
||||
@@ -11,7 +13,7 @@ struct ProcessTableView: View {
|
||||
@State private var departed: ProcessMetrics?
|
||||
@FocusState private var searchFocused: Bool
|
||||
|
||||
private var held: Bool { hovering || selected != nil || searchFocused || !search.isEmpty }
|
||||
private var held: Bool { hovering || selected != nil || !search.isEmpty }
|
||||
private var selectedRow: ProcessMetrics? { rows.first { $0.id == selected } }
|
||||
private var exitedSelection: ProcessIdentity? {
|
||||
guard let selected, snapshot != nil, !rows.contains(where: { $0.id == selected }) else { return nil }
|
||||
@@ -20,22 +22,18 @@ struct ProcessTableView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
Label("panel.processes", systemImage: "list.bullet.rectangle").fontWeight(.semibold)
|
||||
Text(verbatim: "\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)")
|
||||
.foregroundStyle(.secondary).help(Text("panel.coverage"))
|
||||
Spacer(minLength: 0)
|
||||
if held { Button("panel.liveSort") { selected = nil; rebuild(retainOrder: false) } }
|
||||
Picker("panel.sort", selection: $byMemory) {
|
||||
Text("CPU %").tag(false)
|
||||
Text("panel.rss").tag(true)
|
||||
}.labelsHidden().frame(width: 100)
|
||||
}
|
||||
HStack {
|
||||
Text("panel.processScope").font(.system(size: 10)).foregroundStyle(.secondary).lineLimit(2)
|
||||
Spacer(minLength: 4)
|
||||
TextField("panel.search", text: $search).textFieldStyle(.roundedBorder)
|
||||
.frame(width: 210).focused($searchFocused)
|
||||
if wide {
|
||||
HStack(spacing: 10) {
|
||||
processTitle
|
||||
Image(systemName: "info.circle").foregroundStyle(.secondary).help(Text("panel.processScope"))
|
||||
Spacer(minLength: 0)
|
||||
if held { Button { selected = nil; rebuild(retainOrder: false) } label: { Image(systemName: "arrow.up.arrow.down") }.help(Text("panel.liveSort")) }
|
||||
searchField.frame(width: 220)
|
||||
sorting.frame(width: 160)
|
||||
}
|
||||
} else {
|
||||
HStack { processTitle; Spacer(); sorting.frame(width: 140) }
|
||||
searchField
|
||||
}
|
||||
if snapshot?.failed == true { Text("panel.processFailed") }
|
||||
else if snapshot == nil { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
@@ -44,7 +42,15 @@ struct ProcessTableView: View {
|
||||
TableColumn("PID") { row in Text(verbatim: "\(row.id.pid)") }.width(48)
|
||||
TableColumn("panel.name") { row in Text(verbatim: row.name).lineLimit(1) }.width(min: 90, ideal: 140, max: 180)
|
||||
TableColumn("panel.path") { row in Text(verbatim: row.path ?? "--").lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary) }.width(min: 150, ideal: 400)
|
||||
TableColumn("CPU %") { row in Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--") }.width(62)
|
||||
TableColumn("CPU %") { row in
|
||||
HStack(spacing: 6) {
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(Color("MetricCPU").opacity(0.15))
|
||||
if let cpu = row.cpu { Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * min(1, max(0, cpu / Double(max(1, logicalCPUCount))))) }
|
||||
}.frame(width: 45, height: 6).accessibilityHidden(true)
|
||||
Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--").frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
}.width(105)
|
||||
TableColumn("panel.rss") { row in Text(verbatim: row.residentBytes.map { String(format: "%.1f MB", Double($0) / 1_000_000) } ?? "--") }.width(85)
|
||||
TableColumn("panel.threads") { row in
|
||||
HStack { Text(verbatim: row.threads.map(String.init) ?? "--"); if row.restricted { Image(systemName: "lock").accessibilityLabel(Text("panel.restricted")) } }
|
||||
@@ -52,6 +58,7 @@ struct ProcessTableView: View {
|
||||
}
|
||||
.font(.system(size: 11)).monospacedDigit()
|
||||
.tableStyle(.inset(alternatesRowBackgrounds: true))
|
||||
.scrollContentBackground(.hidden)
|
||||
.transaction { $0.animation = nil }
|
||||
.overlay { if snapshot != nil && rows.isEmpty && snapshot?.failed != true { Text("panel.noResults").foregroundStyle(.secondary).allowsHitTesting(false) } }
|
||||
if let row = selectedRow {
|
||||
@@ -67,7 +74,7 @@ struct ProcessTableView: View {
|
||||
.background(Color("PanelCard"), in: .rect(cornerRadius: 14))
|
||||
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(.primary.opacity(0.1)))
|
||||
.onAppear { rebuild(retainOrder: false) }
|
||||
.onChange(of: snapshot?.date) { _, _ in rebuild(retainOrder: held) }
|
||||
.onChange(of: snapshot?.date) { _, _ in rebuild(retainOrder: held && (byMemory ? rows.contains { $0.residentBytes != nil } : rows.contains { $0.cpu != nil })) }
|
||||
.onChange(of: search) { _, _ in rebuild(retainOrder: held) }
|
||||
.onChange(of: byMemory) { _, _ in rebuild(retainOrder: false) }
|
||||
.onChange(of: selected) { _, _ in if let row = selectedRow { departed = row } }
|
||||
@@ -85,6 +92,22 @@ struct ProcessTableView: View {
|
||||
else { NSApp.keyWindow?.close() }
|
||||
}
|
||||
}
|
||||
private var processTitle: some View {
|
||||
HStack(spacing: 8) {
|
||||
Label("panel.processes", systemImage: "list.bullet.rectangle").fontWeight(.semibold)
|
||||
Text(verbatim: "\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)")
|
||||
.foregroundStyle(.secondary).help(Text("panel.coverage"))
|
||||
}
|
||||
}
|
||||
private var searchField: some View {
|
||||
TextField("panel.search", text: $search).textFieldStyle(.roundedBorder).focused($searchFocused)
|
||||
}
|
||||
private var sorting: some View {
|
||||
Picker("panel.sort", selection: $byMemory) {
|
||||
Text("CPU %").tag(false)
|
||||
Text("panel.rss").tag(true)
|
||||
}.labelsHidden().pickerStyle(.segmented).controlSize(.small)
|
||||
}
|
||||
private func rebuild(retainOrder: Bool) {
|
||||
rows = ProcessTableProjection.rows(snapshot?.rows ?? [], query: search, byMemory: byMemory, order: retainOrder ? rows.map(\.id) : [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user