refactor(process): 简化进程表并统一表头排序与应用图标
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Resolves only for visible rows; the task is keyed by process identity and executable path.
|
||||
struct ProcessIcon: View {
|
||||
let process: ProcessMetrics
|
||||
@State private var icon: NSImage?
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if let icon {
|
||||
Image(nsImage: icon).resizable().interpolation(.high)
|
||||
} else {
|
||||
Image(systemName: "app.dashed").resizable().scaledToFit().padding(2)
|
||||
}
|
||||
}
|
||||
.frame(width: 15, height: 15)
|
||||
.accessibilityHidden(true)
|
||||
.task(id: "\(process.id)-\(process.path ?? "")") {
|
||||
// Resolve by the sampled executable, avoiding an icon from a reused PID.
|
||||
guard let path = process.path else { icon = nil; return }
|
||||
let url = URL(fileURLWithPath: path)
|
||||
let app = sequence(first: url, next: { $0.path == "/" ? nil : $0.deletingLastPathComponent() })
|
||||
.first { $0.pathExtension == "app" }
|
||||
icon = NSWorkspace.shared.icon(forFile: (app ?? url).path)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user