mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: add a sensor value to the chart in the popup view even if the popup is closed
This commit is contained in:
@@ -97,11 +97,11 @@ public class LineChartView: NSView {
|
||||
underLinePath.fill()
|
||||
}
|
||||
|
||||
public func addValue(_ value: Double) {
|
||||
public func addValue(_ value: Double, redraw: Bool = true) {
|
||||
self.points.remove(at: 0)
|
||||
self.points.append(value)
|
||||
|
||||
if self.window?.isVisible ?? true {
|
||||
if redraw && self.window?.isVisible ?? true {
|
||||
self.display()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,12 @@ internal class Popup: NSStackView, Popup_p {
|
||||
}
|
||||
|
||||
internal func usageCallback(_ values: [Sensor_p]) {
|
||||
values.filter({ $0 is Sensor }).forEach { (s: Sensor_p) in
|
||||
if let sensor = self.list[s.key] as? SensorView {
|
||||
sensor.addHistoryPoint(s)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async(execute: {
|
||||
if self.window?.isVisible ?? false {
|
||||
values.forEach { (s: Sensor_p) in
|
||||
@@ -165,6 +171,9 @@ internal class SensorView: NSStackView {
|
||||
|
||||
public func update(_ sensor: Sensor_p) {
|
||||
self.valueView.update(sensor.formattedValue)
|
||||
}
|
||||
|
||||
public func addHistoryPoint(_ sensor: Sensor_p) {
|
||||
self.chartView.update(sensor.value)
|
||||
}
|
||||
|
||||
@@ -274,7 +283,7 @@ internal class ChartSensorView: NSStackView {
|
||||
}
|
||||
|
||||
public func update(_ value: Double) {
|
||||
self.chart?.addValue(value/100)
|
||||
self.chart?.addValue(value/100, redraw: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user