mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: fixed wrong ram pressure levels colorizing. Moved from int to the internal levels variable (DispatchSource.MemoryPressureEvent) (#1010)
This commit is contained in:
@@ -19,7 +19,7 @@ public class BarChart: WidgetWrapper {
|
||||
|
||||
private var colors: [Color] = Color.allCases
|
||||
private var value: [[ColorValue]] = [[]]
|
||||
private var pressureLevel: Int = 0
|
||||
private var pressureLevel: DispatchSource.MemoryPressureEvent = .normal
|
||||
private var colorZones: colorZones = (0.6, 0.8)
|
||||
|
||||
private var boxSettingsView: NSView? = nil
|
||||
@@ -214,7 +214,7 @@ public class BarChart: WidgetWrapper {
|
||||
})
|
||||
}
|
||||
|
||||
public func setPressure(_ level: Int) {
|
||||
public func setPressure(_ level: DispatchSource.MemoryPressureEvent) {
|
||||
guard self.pressureLevel != level else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LineChart: WidgetWrapper {
|
||||
), num: 60)
|
||||
private var colors: [Color] = Color.allCases
|
||||
private var value: Double = 0
|
||||
private var pressureLevel: Int = 0
|
||||
private var pressureLevel: DispatchSource.MemoryPressureEvent = .normal
|
||||
|
||||
private var historyNumbers: [KeyValue_p] = [
|
||||
KeyValue_t(key: "30", value: "30"),
|
||||
@@ -242,7 +242,7 @@ public class LineChart: WidgetWrapper {
|
||||
})
|
||||
}
|
||||
|
||||
public func setPressure(_ level: Int) {
|
||||
public func setPressure(_ level: DispatchSource.MemoryPressureEvent) {
|
||||
guard self.pressureLevel != level else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Mini: WidgetWrapper {
|
||||
private var colorZones: colorZones = (0.6, 0.8)
|
||||
|
||||
private var value: Double = 0
|
||||
private var pressureLevel: Int = 0
|
||||
private var pressureLevel: DispatchSource.MemoryPressureEvent = .normal
|
||||
private var defaultLabel: String
|
||||
private var label: String
|
||||
|
||||
@@ -151,7 +151,7 @@ public class Mini: WidgetWrapper {
|
||||
})
|
||||
}
|
||||
|
||||
public func setPressure(_ level: Int) {
|
||||
public func setPressure(_ level: DispatchSource.MemoryPressureEvent) {
|
||||
if self.pressureLevel == level {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ extension String: LocalizedError {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Int {
|
||||
public extension DispatchSource.MemoryPressureEvent {
|
||||
func pressureColor() -> NSColor {
|
||||
switch self {
|
||||
case 1:
|
||||
case .normal:
|
||||
return NSColor.systemGreen
|
||||
case 2:
|
||||
case .warning:
|
||||
return NSColor.systemYellow
|
||||
case 3:
|
||||
case .critical:
|
||||
return NSColor.systemRed
|
||||
default:
|
||||
return controlAccentColor
|
||||
|
||||
@@ -26,7 +26,7 @@ public struct RAM_Usage: value_t {
|
||||
var cache: Double
|
||||
var pressure: Double
|
||||
|
||||
var pressureLevel: Int
|
||||
var pressureLevel: DispatchSource.MemoryPressureEvent
|
||||
var swap: Swap
|
||||
|
||||
public var widgetValue: Double {
|
||||
|
||||
@@ -264,7 +264,7 @@ public class PressureView: NSView {
|
||||
circle_segment(value: 1/3, color: NSColor.systemRed)
|
||||
]
|
||||
|
||||
private var level: Int = 1
|
||||
private var level: DispatchSource.MemoryPressureEvent = .normal
|
||||
|
||||
public override func draw(_ rect: CGRect) {
|
||||
let arcWidth: CGFloat = 7.0
|
||||
@@ -301,15 +301,15 @@ public class PressureView: NSView {
|
||||
let needlePath = NSBezierPath()
|
||||
|
||||
switch self.level {
|
||||
case 1: // NORMAL
|
||||
case .normal:
|
||||
needlePath.move(to: CGPoint(x: self.bounds.width * 0.15, y: self.bounds.width * 0.40))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2, y: self.bounds.height/2 - needleEndSize))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2, y: self.bounds.height/2 + needleEndSize))
|
||||
case 2: // WARN
|
||||
case .warning:
|
||||
needlePath.move(to: CGPoint(x: self.bounds.width/2, y: self.bounds.width * 0.85))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2 - needleEndSize, y: self.bounds.height/2))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2 + needleEndSize, y: self.bounds.height/2))
|
||||
case 4: // CRITICAL
|
||||
case .critical:
|
||||
needlePath.move(to: CGPoint(x: self.bounds.width * 0.85, y: self.bounds.width * 0.40))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2, y: self.bounds.height/2 - needleEndSize))
|
||||
needlePath.line(to: CGPoint(x: self.bounds.width/2, y: self.bounds.height/2 + needleEndSize))
|
||||
@@ -336,11 +336,11 @@ public class PressureView: NSView {
|
||||
]
|
||||
|
||||
let rect = CGRect(x: (self.frame.width-6)/2, y: (self.frame.height-26)/2, width: 6, height: 12)
|
||||
let str = NSAttributedString.init(string: "\(self.level)", attributes: stringAttributes)
|
||||
let str = NSAttributedString.init(string: "\(self.level.rawValue)", attributes: stringAttributes)
|
||||
str.draw(with: rect)
|
||||
}
|
||||
|
||||
public func setLevel(_ level: Int) {
|
||||
public func setLevel(_ level: DispatchSource.MemoryPressureEvent) {
|
||||
self.level = level
|
||||
if self.window?.isVisible ?? true {
|
||||
self.display()
|
||||
|
||||
@@ -78,7 +78,7 @@ internal class UsageReader: Reader<RAM_Usage> {
|
||||
cache: purgeable + external,
|
||||
pressure: 100.0 * (wired + compressed) / self.totalSize,
|
||||
|
||||
pressureLevel: pressureLevel,
|
||||
pressureLevel: DispatchSource.MemoryPressureEvent(rawValue: UInt(pressureLevel)),
|
||||
|
||||
swap: Swap(
|
||||
total: Double(swap.xsu_total),
|
||||
|
||||
Reference in New Issue
Block a user