mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
- add icon to top processes
This commit is contained in:
@@ -246,6 +246,12 @@ public class ProcessView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
public var icon: NSImage? {
|
||||
get { return NSImage() }
|
||||
set {
|
||||
self.imageView?.image = newValue
|
||||
}
|
||||
}
|
||||
public var label: String {
|
||||
get { return "" }
|
||||
set {
|
||||
@@ -259,6 +265,7 @@ public class ProcessView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
private var imageView: NSImageView? = nil
|
||||
private var labelView: LabelField? = nil
|
||||
private var valueView: ValueField? = nil
|
||||
|
||||
@@ -267,12 +274,15 @@ public class ProcessView: NSView {
|
||||
|
||||
let rowView: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: 16))
|
||||
|
||||
let labelView: LabelField = LabelField(frame: NSRect(x: 0, y: 0.5, width: rowView.frame.width - 70, height: 15), "")
|
||||
let valueView: ValueField = ValueField(frame: NSRect(x: rowView.frame.width - 70, y: 0, width: 70, height: 16), "")
|
||||
let imageView: NSImageView = NSImageView(frame: NSRect(x: 2, y: 2, width: 12, height: 12))
|
||||
let labelView: LabelField = LabelField(frame: NSRect(x: 18, y: 0.5, width: rowView.frame.width - 70 - 18, height: 15), "")
|
||||
let valueView: ValueField = ValueField(frame: NSRect(x: 18 + labelView.frame.width, y: 0, width: 70, height: 16), "")
|
||||
|
||||
rowView.addSubview(imageView)
|
||||
rowView.addSubview(labelView)
|
||||
rowView.addSubview(valueView)
|
||||
|
||||
self.imageView = imageView
|
||||
self.labelView = labelView
|
||||
self.valueView = valueView
|
||||
|
||||
|
||||
@@ -134,7 +134,9 @@ open class Reader<T>: ReaderInternal_p {
|
||||
}
|
||||
|
||||
if let interval = self.interval, self.repeatTask == nil {
|
||||
os_log(.debug, log: self.log, "Set up update interval: %.0f sec", interval)
|
||||
if !self.popup && !self.optional {
|
||||
os_log(.debug, log: self.log, "Set up update interval: %.0f sec", interval)
|
||||
}
|
||||
|
||||
self.repeatTask = Repeater.init(interval: .seconds(interval), observer: { _ in
|
||||
self.read()
|
||||
|
||||
@@ -195,6 +195,7 @@ internal class Popup: NSView {
|
||||
if self.processes.indices.contains(index) {
|
||||
self.processes[index].label = process.name != nil ? process.name! : process.command
|
||||
self.processes[index].value = "\(process.usage)%"
|
||||
self.processes[index].icon = process.icon
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -174,11 +174,13 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
}
|
||||
|
||||
var name: String? = nil
|
||||
var icon: NSImage? = nil
|
||||
if let app = NSRunningApplication(processIdentifier: pid_t(pid) ) {
|
||||
name = app.localizedName ?? nil
|
||||
icon = app.icon
|
||||
}
|
||||
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage))
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage, icon: icon))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,13 +243,15 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
guard let usage = Double(usageString.filter("01234567890.".contains)) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var name: String? = nil
|
||||
var icon: NSImage? = nil
|
||||
if let app = NSRunningApplication(processIdentifier: pid_t(pid) ) {
|
||||
name = app.localizedName ?? nil
|
||||
icon = app.icon
|
||||
}
|
||||
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage))
|
||||
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage, icon: icon))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ internal class Popup: NSView {
|
||||
if self.processes.indices.contains(index) {
|
||||
self.processes[index].label = process.name != nil ? process.name! : process.command
|
||||
self.processes[index].value = "\(process.usage)%"
|
||||
self.processes[index].icon = process.icon
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -195,11 +195,13 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
let usage = Double(usageString.replacingOccurrences(of: ",", with: ".")) ?? 0
|
||||
|
||||
var name: String? = nil
|
||||
var icon: NSImage? = nil
|
||||
if let app = NSRunningApplication(processIdentifier: pid_t(pid) ) {
|
||||
name = app.localizedName ?? nil
|
||||
icon = app.icon
|
||||
}
|
||||
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage))
|
||||
processes.append(TopProcess(pid: pid, command: command, name: name, usage: usage, icon: icon))
|
||||
}
|
||||
|
||||
if index == 5 { stop = true }
|
||||
|
||||
@@ -146,6 +146,7 @@ internal class Popup: NSView {
|
||||
if self.processes.indices.contains(index) {
|
||||
self.processes[index].label = process.name != nil ? process.name! : process.command
|
||||
self.processes[index].value = Units(bytes: Int64(process.usage)).getReadableMemory()
|
||||
self.processes[index].icon = process.icon
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -129,11 +129,13 @@ public class ProcessReader: Reader<[TopProcess]> {
|
||||
}
|
||||
|
||||
var name: String? = nil
|
||||
var icon: NSImage? = nil
|
||||
if let app = NSRunningApplication(processIdentifier: pid_t(pid) ) {
|
||||
name = app.localizedName ?? nil
|
||||
icon = app.icon
|
||||
}
|
||||
|
||||
let process = TopProcess(pid: pid, command: command, name: name, usage: usage * Double(1024 * 1024))
|
||||
let process = TopProcess(pid: pid, command: command, name: name, usage: usage * Double(1024 * 1024), icon: icon)
|
||||
processes.append(process)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public struct Network_Process {
|
||||
var pid: String = ""
|
||||
var download: Int = 0
|
||||
var upload: Int = 0
|
||||
var icon: NSImage? = nil
|
||||
}
|
||||
|
||||
public class Network: Module {
|
||||
|
||||
@@ -230,6 +230,7 @@ internal class Popup: NSView {
|
||||
self.processes[index].label = process.name
|
||||
self.processes[index].upload = Units(bytes: Int64(process.upload)).getReadableSpeed()
|
||||
self.processes[index].download = Units(bytes: Int64(process.download)).getReadableSpeed()
|
||||
self.processes[index].icon = process.icon
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -277,6 +278,12 @@ public class NetworkProcessView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
public var icon: NSImage? {
|
||||
get { return NSImage() }
|
||||
set {
|
||||
self.imageView?.image = newValue
|
||||
}
|
||||
}
|
||||
public var label: String {
|
||||
get { return "" }
|
||||
set {
|
||||
@@ -296,6 +303,7 @@ public class NetworkProcessView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
private var imageView: NSImageView? = nil
|
||||
private var labelView: LabelField? = nil
|
||||
private var uploadView: ValueField? = nil
|
||||
private var downloadView: ValueField? = nil
|
||||
@@ -305,16 +313,19 @@ public class NetworkProcessView: NSView {
|
||||
|
||||
let rowView: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: 16))
|
||||
|
||||
let labelView: LabelField = LabelField(frame: NSRect(x: 0, y: 0.5, width: rowView.frame.width - 120, height: 15), "")
|
||||
let imageView: NSImageView = NSImageView(frame: NSRect(x: 2, y: 2, width: 12, height: 12))
|
||||
let labelView: LabelField = LabelField(frame: NSRect(x: 18, y: 0.5, width: rowView.frame.width - 138, height: 15), "")
|
||||
let uploadView: ValueField = ValueField(frame: NSRect(x: rowView.frame.width - 120, y: 1.75, width: 60, height: 12), "")
|
||||
let downloadView: ValueField = ValueField(frame: NSRect(x: rowView.frame.width - 60, y: 1.75, width: 60, height: 12), "")
|
||||
uploadView.font = NSFont.systemFont(ofSize: 10, weight: .regular)
|
||||
downloadView.font = NSFont.systemFont(ofSize: 10, weight: .regular)
|
||||
|
||||
rowView.addSubview(imageView)
|
||||
rowView.addSubview(labelView)
|
||||
rowView.addSubview(uploadView)
|
||||
rowView.addSubview(downloadView)
|
||||
|
||||
self.imageView = imageView
|
||||
self.labelView = labelView
|
||||
self.uploadView = uploadView
|
||||
self.downloadView = downloadView
|
||||
|
||||
@@ -245,6 +245,7 @@ public class ProcessReader: Reader<[Network_Process]> {
|
||||
}
|
||||
if let app = NSRunningApplication(processIdentifier: pid_t(process.pid) ?? 0) {
|
||||
process.name = app.localizedName ?? nameArray.dropLast().joined(separator: ".")
|
||||
process.icon = app.icon
|
||||
} else {
|
||||
process.name = nameArray.dropLast().joined(separator: ".")
|
||||
}
|
||||
@@ -273,7 +274,7 @@ public class ProcessReader: Reader<[Network_Process]> {
|
||||
let time = download == 0 && upload == 0 ? pp.time : Date()
|
||||
list[i].time = time
|
||||
|
||||
processes.append(Network_Process(time: time, name: p.name, pid: p.pid, download: download, upload: upload))
|
||||
processes.append(Network_Process(time: time, name: p.name, pid: p.pid, download: download, upload: upload, icon: p.icon))
|
||||
}
|
||||
}
|
||||
self.previous = list
|
||||
|
||||
@@ -824,11 +824,13 @@ public struct TopProcess {
|
||||
public var command: String
|
||||
public var name: String?
|
||||
public var usage: Double
|
||||
public var icon: NSImage?
|
||||
|
||||
public init(pid: Int, command: String, name: String?, usage: Double) {
|
||||
public init(pid: Int, command: String, name: String?, usage: Double, icon: NSImage?) {
|
||||
self.pid = pid
|
||||
self.command = command
|
||||
self.name = name
|
||||
self.usage = usage
|
||||
self.icon = icon
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user