mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added module types to the readers
This commit is contained in:
@@ -55,3 +55,29 @@ public struct Constants {
|
||||
|
||||
public static let defaultProcessIcon = NSWorkspace.shared.icon(forFile: "/bin/bash")
|
||||
}
|
||||
|
||||
public enum ModuleType: Int {
|
||||
case CPU
|
||||
case RAM
|
||||
case GPU
|
||||
case disk
|
||||
case sensors
|
||||
case network
|
||||
case battery
|
||||
case bluetooth
|
||||
case clock
|
||||
|
||||
var rawValue: String {
|
||||
switch self {
|
||||
case .CPU: return "CPU"
|
||||
case .RAM: return "RAM"
|
||||
case .GPU: return "GPU"
|
||||
case .disk: return "Disk"
|
||||
case .sensors: return "Sensors"
|
||||
case .network: return "Network"
|
||||
case .battery: return "Battery"
|
||||
case .bluetooth: return "Bluetooth"
|
||||
case .clock: return "Clock"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public protocol Reader_p {
|
||||
func terminate()
|
||||
|
||||
func getValue<T>() -> T
|
||||
func getHistory() -> [value_t]
|
||||
|
||||
func start()
|
||||
func pause()
|
||||
@@ -44,11 +43,15 @@ public protocol ReaderInternal_p {
|
||||
func read()
|
||||
}
|
||||
|
||||
open class Reader<T>: NSObject, ReaderInternal_p {
|
||||
open class Reader<T: Codable>: NSObject, ReaderInternal_p {
|
||||
public var log: NextLog {
|
||||
return NextLog.shared.copy(category: "\(String(describing: self))")
|
||||
NextLog.shared.copy(category: "\(String(describing: self))")
|
||||
}
|
||||
public var value: T?
|
||||
public var name: String {
|
||||
String(NSStringFromClass(type(of: self)).split(separator: ".").last ?? "unknown")
|
||||
}
|
||||
|
||||
public var interval: Double? = nil
|
||||
public var defaultInterval: Double = 1
|
||||
public var optional: Bool = false
|
||||
@@ -75,9 +78,7 @@ open class Reader<T>: NSObject, ReaderInternal_p {
|
||||
}
|
||||
}
|
||||
|
||||
private var history: [T]? = []
|
||||
|
||||
public init(popup: Bool = false) {
|
||||
public init(_ module: ModuleType, popup: Bool = false) {
|
||||
self.popup = popup
|
||||
|
||||
super.init()
|
||||
@@ -120,12 +121,8 @@ open class Reader<T>: NSObject, ReaderInternal_p {
|
||||
}
|
||||
|
||||
self.value = value
|
||||
if value != nil {
|
||||
if self.history?.count ?? 0 >= 300 {
|
||||
self.history!.remove(at: 0)
|
||||
}
|
||||
self.history?.append(value!)
|
||||
self.callbackHandler(value!)
|
||||
if let value {
|
||||
self.callbackHandler(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,10 +184,6 @@ extension Reader: Reader_p {
|
||||
return self.value as! T
|
||||
}
|
||||
|
||||
public func getHistory<T>() -> [T] {
|
||||
return self.history as! [T]
|
||||
}
|
||||
|
||||
public func lock() {
|
||||
self.locked = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user