This commit is contained in:
Serhiy Mytrovtsiy
2025-01-26 14:32:51 +01:00
parent 479b812f84
commit 9325e2001c
23 changed files with 41 additions and 48 deletions

View File

@@ -69,7 +69,7 @@ public enum ModuleType: Int {
case combined
public var rawValue: String {
public var stringValue: String {
switch self {
case .CPU: return "CPU"
case .RAM: return "RAM"

View File

@@ -18,7 +18,7 @@ open class NotificationsWrapper: NSStackView {
private var ids: [String: Bool?] = [:]
public init(_ module: ModuleType, _ ids: [String] = []) {
self.module = module.rawValue
self.module = module.stringValue
super.init(frame: NSRect.zero)
self.initIDs(ids)

View File

@@ -28,8 +28,8 @@ open class PopupWrapper: NSStackView, Popup_p {
open var sizeCallback: ((NSSize) -> Void)? = nil
public init(_ typ: ModuleType, frame: NSRect) {
self.title = typ.rawValue
self.keyboardShortcut = Store.shared.array(key: "\(typ.rawValue)_popup_keyboardShortcut", defaultValue: []) as? [UInt16] ?? []
self.title = typ.stringValue
self.keyboardShortcut = Store.shared.array(key: "\(typ.stringValue)_popup_keyboardShortcut", defaultValue: []) as? [UInt16] ?? []
super.init(frame: frame)
}

View File

@@ -20,8 +20,8 @@ open class PortalWrapper: NSStackView, Portal_p {
private let header: PortalHeader
public init(_ type: ModuleType, height: CGFloat = Constants.Popup.portalHeight) {
self.name = type.rawValue
self.header = PortalHeader(type.rawValue)
self.name = type.stringValue
self.header = PortalHeader(type.stringValue)
super.init(frame: NSRect(x: 0, y: 0, width: Constants.Popup.width, height: height))

View File

@@ -75,8 +75,8 @@ open class Reader<T: Codable>: NSObject, ReaderInternal_p {
self.callbackHandler = callback
super.init()
DB.shared.setup(T.self, "\(module.rawValue)@\(self.name)")
if let lastValue = DB.shared.findOne(T.self, key: "\(module.rawValue)@\(self.name)") {
DB.shared.setup(T.self, "\(module.stringValue)@\(self.name)")
if let lastValue = DB.shared.findOne(T.self, key: "\(module.stringValue)@\(self.name)") {
self.value = lastValue
callback(lastValue)
}
@@ -86,7 +86,7 @@ open class Reader<T: Codable>: NSObject, ReaderInternal_p {
}
deinit {
DB.shared.insert(key: "\(self.module.rawValue)@\(self.name)", value: self.value, ts: self.history)
DB.shared.insert(key: "\(self.module.stringValue)@\(self.name)", value: self.value, ts: self.history)
}
public func initStoreValues(title: String) {
@@ -102,10 +102,10 @@ open class Reader<T: Codable>: NSObject, ReaderInternal_p {
if let value {
self.callbackHandler(value)
if let ts = self.lastDBWrite, let interval = self.interval, Date().timeIntervalSince(ts) > interval * 10 {
DB.shared.insert(key: "\(self.module.rawValue)@\(self.name)", value: value, ts: self.history)
DB.shared.insert(key: "\(self.module.stringValue)@\(self.name)", value: value, ts: self.history)
self.lastDBWrite = Date()
} else if self.lastDBWrite == nil {
DB.shared.insert(key: "\(self.module.rawValue)@\(self.name)", value: value, ts: self.history)
DB.shared.insert(key: "\(self.module.stringValue)@\(self.name)", value: value, ts: self.history)
self.lastDBWrite = Date()
}
}
@@ -162,7 +162,7 @@ open class Reader<T: Codable>: NSObject, ReaderInternal_p {
}
public func save(_ value: T) {
DB.shared.insert(key: "\(self.module.rawValue)@\(self.name)", value: value, ts: self.history, force: true)
DB.shared.insert(key: "\(self.module.stringValue)@\(self.name)", value: value, ts: self.history, force: true)
}
}