feat(menubar): 拆分紧凑双页面板并按页采样
This commit is contained in:
@@ -25,7 +25,7 @@ import SwiftUI
|
||||
table.usesAlternatingRowBackgroundColors = true; table.backgroundColor = .clear
|
||||
table.allowsMultipleSelection = false; table.allowsEmptySelection = true
|
||||
table.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle
|
||||
for (key, width) in [("pid", 48.0), ("name", 140), ("path", 400), ("cpu", 65), ("memory", 85), ("threads", 65)] {
|
||||
for (key, width) in [("pid", 48.0), ("name", 140), ("path", 250), ("cpu", 65), ("memory", 85), ("power", 90), ("threads", 65)] {
|
||||
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(key))
|
||||
column.width = width
|
||||
column.minWidth = key == "path" ? 150 : key == "name" ? 90 : width
|
||||
@@ -148,9 +148,18 @@ import SwiftUI
|
||||
case "path": text = process.path ?? "--"
|
||||
case "cpu": text = process.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--"
|
||||
case "memory": text = process.footprintBytes.map { String(format: "%.1f MB", Double($0) / 1_048_576) } ?? "--"
|
||||
case "power": text = process.formattedPower
|
||||
default: text = process.threads.map(String.init) ?? "--"
|
||||
}
|
||||
if cell.textField?.stringValue != text { cell.textField?.stringValue = text }
|
||||
if key == "power" {
|
||||
let help = AppLocalization.string("energy.scopeHelp", locale: parent.locale)
|
||||
let window = process.powerWindow.map {
|
||||
String(format: AppLocalization.string("energy.window %@", locale: parent.locale), String(format: "%.1f", $0))
|
||||
}
|
||||
let tooltip = window.map { help + "\n" + $0 } ?? help
|
||||
if cell.toolTip != tooltip { cell.toolTip = tooltip }
|
||||
}
|
||||
if key == "name" {
|
||||
let image = PanelResourceAudit.omitted == "icons" ? nil : process.path.flatMap { ProcessIconCache.shared.image(for: $0) }
|
||||
let desired = image ?? Self.placeholder
|
||||
@@ -203,10 +212,10 @@ import SwiftUI
|
||||
NSPasteboard.general.clearContents(); NSPasteboard.general.setString(value, forType: .string)
|
||||
}
|
||||
private static func name(_ key: ProcessSort.Key) -> String {
|
||||
switch key { case .pid: "pid"; case .name: "name"; case .path: "path"; case .cpu: "cpu"; case .memory: "memory"; case .threads: "threads" }
|
||||
switch key { case .pid: "pid"; case .name: "name"; case .path: "path"; case .cpu: "cpu"; case .memory: "memory"; case .threads: "threads"; case .power: "power" }
|
||||
}
|
||||
private static func key(_ name: String) -> ProcessSort.Key? {
|
||||
switch name { case "pid": .pid; case "name": .name; case "path": .path; case "cpu": .cpu; case "memory": .memory; case "threads": .threads; default: nil }
|
||||
switch name { case "pid": .pid; case "name": .name; case "path": .path; case "cpu": .cpu; case "memory": .memory; case "threads": .threads; case "power": .power; default: nil }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +225,8 @@ import SwiftUI
|
||||
self.key = key
|
||||
super.init(frame: .zero)
|
||||
let text = NSTextField(labelWithString: "")
|
||||
text.font = ["pid", "cpu", "memory", "threads"].contains(key) ? .monospacedDigitSystemFont(ofSize: 11, weight: .regular) : .systemFont(ofSize: 11)
|
||||
text.alignment = ["cpu", "memory", "threads"].contains(key) ? .right : .left
|
||||
text.font = ["pid", "cpu", "memory", "threads", "power"].contains(key) ? .monospacedDigitSystemFont(ofSize: 11, weight: .regular) : .systemFont(ofSize: 11)
|
||||
text.alignment = ["cpu", "memory", "threads", "power"].contains(key) ? .right : .left
|
||||
text.lineBreakMode = .byTruncatingMiddle
|
||||
text.textColor = key == "path" ? .secondaryLabelColor : .labelColor
|
||||
addSubview(text); textField = text
|
||||
|
||||
Reference in New Issue
Block a user