- update dashboard in Memory popup

This commit is contained in:
Serhiy Mytrovtsiy
2020-08-13 16:37:24 +02:00
parent cd1684dc09
commit 919f7a2007
2 changed files with 67 additions and 39 deletions

View File

@@ -14,21 +14,21 @@ import StatsKit
import ModuleKit
public struct RAM_Usage: value_t {
var active: Double?
var inactive: Double?
var wired: Double?
var compressed: Double?
var active: Double
var inactive: Double
var wired: Double
var compressed: Double
var usage: Double?
var total: Double?
var used: Double?
var free: Double?
var usage: Double
var total: Double
var used: Double
var free: Double
var pressureLevel: Int
public var widget_value: Double {
get {
return self.usage ?? 0
return self.usage
}
}
}
@@ -84,15 +84,15 @@ public class Memory: Module {
self.popupView.loadCallback(value!)
if let widget = self.widget as? Mini {
widget.setValue(value!.usage ?? 0, sufix: "%")
widget.setValue(value!.usage , sufix: "%")
widget.setPressure(value?.pressureLevel ?? 0)
}
if let widget = self.widget as? LineChart {
widget.setValue(value!.usage ?? 0)
widget.setValue(value!.usage )
widget.setPressure(value?.pressureLevel ?? 0)
}
if let widget = self.widget as? BarChart {
widget.setValue([value!.usage ?? 0])
widget.setValue([value!.usage ])
widget.setPressure(value?.pressureLevel ?? 0)
}
}

View File

@@ -15,7 +15,8 @@ import StatsKit
internal class Popup: NSView {
private let dashboardHeight: CGFloat = 90
private let detailsHeight: CGFloat = 66
private let chartHeight: CGFloat = 90
private let detailsHeight: CGFloat = 22*6
private let processesHeight: CGFloat = 22*5
private var totalField: NSTextField? = nil
@@ -28,14 +29,21 @@ internal class Popup: NSView {
private var compressedField: NSTextField? = nil
private var chart: LineChartView? = nil
private var circle: CircleGraphView? = nil
private var initialized: Bool = false
private var processes: [ProcessView] = []
public init() {
super.init(frame: NSRect(x: 0, y: 0, width: Constants.Popup.width, height: dashboardHeight + (Constants.Popup.separatorHeight*2) + detailsHeight + processesHeight))
super.init(frame: NSRect(
x: 0,
y: 0,
width: Constants.Popup.width,
height: dashboardHeight + chartHeight + detailsHeight + processesHeight + (Constants.Popup.separatorHeight*3)
))
initFirstView()
initDashboard()
initChart()
initDetails()
initProcesses()
}
@@ -48,36 +56,50 @@ internal class Popup: NSView {
self.chart?.display()
}
private func initFirstView() {
let rightWidth: CGFloat = 116
private func initDashboard() {
let view: NSView = NSView(frame: NSRect(x: 0, y: self.frame.height - self.dashboardHeight, width: self.frame.width, height: self.dashboardHeight))
view.wantsLayer = true
let leftPanel = NSView(frame: NSRect(x: 0, y: 0, width: view.frame.width - rightWidth - Constants.Popup.margins, height: view.frame.height))
let container: NSView = NSView(frame: NSRect(x: 0, y: 10, width: view.frame.width, height: self.dashboardHeight-20))
self.circle = CircleGraphView(frame: NSRect(x: (container.frame.width - container.frame.height)/2, y: 0, width: container.frame.height, height: container.frame.height), segments: [])
self.circle!.toolTip = "RAM usage"
container.addSubview(self.circle!)
self.chart = LineChartView(frame: NSRect(x: 4, y: 3, width: leftPanel.frame.width, height: leftPanel.frame.height), num: 120)
leftPanel.addSubview(self.chart!)
view.addSubview(container)
self.addSubview(view)
}
private func initChart() {
let y: CGFloat = self.frame.height - self.dashboardHeight - Constants.Popup.separatorHeight
let separator = SeparatorView("History", origin: NSPoint(x: 0, y: y), width: self.frame.width)
self.addSubview(separator)
let rightPanel: NSView = NSView(frame: NSRect(x: view.frame.width - rightWidth, y: 0, width: rightWidth, height: view.frame.height))
self.activeField = addFirstRow(mView: rightPanel, y: ((rightPanel.frame.height - 16)/2)+29, title: "Active:", value: "")
self.inactiveField = addFirstRow(mView: rightPanel, y: (rightPanel.frame.height - 16)/2+10, title: "Inactive:", value: "")
self.wiredField = addFirstRow(mView: rightPanel, y: ((rightPanel.frame.height - 16)/2)-10, title: "Wired:", value: "")
self.compressedField = addFirstRow(mView: rightPanel, y: ((rightPanel.frame.height - 16)/2)-29, title: "Compressed:", value: "")
let view: NSView = NSView(frame: NSRect(x: 0, y: y - self.chartHeight, width: self.frame.width, height: self.chartHeight))
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.lightGray.withAlphaComponent(0.1).cgColor
view.layer?.cornerRadius = 3
self.chart = LineChartView(frame: NSRect(x: 1, y: 0, width: view.frame.width, height: view.frame.height), num: 120)
view.addSubview(self.chart!)
view.addSubview(leftPanel)
view.addSubview(rightPanel)
self.addSubview(view)
}
private func initDetails() {
let y: CGFloat = self.frame.height - self.dashboardHeight - Constants.Popup.separatorHeight
let y: CGFloat = self.frame.height - self.dashboardHeight - self.chartHeight - (Constants.Popup.separatorHeight*2)
let separator = SeparatorView("Details", origin: NSPoint(x: 0, y: y), width: self.frame.width)
self.addSubview(separator)
let view: NSView = NSView(frame: NSRect(x: 0, y: separator.frame.origin.y - self.detailsHeight, width: self.frame.width, height: self.detailsHeight))
self.totalField = PopupRow(view, n: 2, title: "Total:", value: "")
self.usedField = PopupRow(view, n: 1, title: "Used:", value: "")
self.freeField = PopupRow(view, n: 0, title: "Free:", value: "")
self.totalField = PopupRow(view, n: 5, title: "Total:", value: "")
self.usedField = PopupRow(view, n: 4, title: "Used:", value: "")
self.activeField = PopupWithColorRow(view, color: NSColor.systemBlue, n: 3, title: "App:", value: "")
self.wiredField = PopupWithColorRow(view, color: NSColor.systemOrange, n: 2, title: "Wired:", value: "")
self.compressedField = PopupWithColorRow(view, color: NSColor.systemPink, n: 1, title: "Compressed:", value: "")
self.freeField = PopupWithColorRow(view, color: NSColor.lightGray.withAlphaComponent(0.5), n: 0, title: "Free:", value: "")
self.addSubview(view)
}
@@ -123,18 +145,24 @@ internal class Popup: NSView {
public func loadCallback(_ value: RAM_Usage) {
DispatchQueue.main.async(execute: {
if (self.window?.isVisible ?? false) || !self.initialized {
self.activeField?.stringValue = Units(bytes: Int64(value.active!)).getReadableMemory()
self.inactiveField?.stringValue = Units(bytes: Int64(value.inactive!)).getReadableMemory()
self.wiredField?.stringValue = Units(bytes: Int64(value.wired!)).getReadableMemory()
self.compressedField?.stringValue = Units(bytes: Int64(value.compressed!)).getReadableMemory()
self.activeField?.stringValue = Units(bytes: Int64(value.active)).getReadableMemory()
self.inactiveField?.stringValue = Units(bytes: Int64(value.inactive)).getReadableMemory()
self.wiredField?.stringValue = Units(bytes: Int64(value.wired)).getReadableMemory()
self.compressedField?.stringValue = Units(bytes: Int64(value.compressed)).getReadableMemory()
self.totalField?.stringValue = Units(bytes: Int64(value.total!)).getReadableMemory()
self.usedField?.stringValue = Units(bytes: Int64(value.used!)).getReadableMemory()
self.freeField?.stringValue = Units(bytes: Int64(value.free!)).getReadableMemory()
self.totalField?.stringValue = Units(bytes: Int64(value.total)).getReadableMemory()
self.usedField?.stringValue = Units(bytes: Int64(value.used)).getReadableMemory()
self.freeField?.stringValue = Units(bytes: Int64(value.free)).getReadableMemory()
self.initialized = true
}
self.chart?.addValue(value.usage!)
self.circle?.setValue(value.usage)
self.circle?.setSegments([
circle_segment(value: value.active/value.total, color: NSColor.systemBlue),
circle_segment(value: value.wired/value.total, color: NSColor.systemOrange),
circle_segment(value: value.compressed/value.total, color: NSColor.systemPink)
])
self.chart?.addValue(value.usage)
})
}