feat: rewrite GPU popup view from scratch. Was added more information about each GPU (#191). Only available chart (temperature and usage) will be visible for GPU.

This commit is contained in:
Serhiy Mytrovtsiy
2021-01-09 12:37:15 +01:00
parent 9741f47f9c
commit 28155fb9df
5 changed files with 396 additions and 159 deletions

View File

@@ -23,25 +23,40 @@ public enum GPU_types: GPU_type {
}
public struct GPU_Info {
public let model: String
public let IOClass: String
public let id: String
public let type: GPU_type
public let IOClass: String
public var vendor: String? = nil
public let model: String
public var state: Bool = true
public var utilization: Double = 0
public var temperature: Int = 0
public var fanSpeed: Int? = nil
public var coreClock: Int? = nil
public var memoryClock: Int? = nil
public var temperature: Double? = nil
public var utilization: Double? = nil
init(type: GPU_type, IOClass: String, vendor: String? = nil, model: String) {
self.id = UUID().uuidString
self.type = type
self.IOClass = IOClass
self.vendor = vendor
self.model = model
}
}
public struct GPUs: value_t {
public var list: [GPU_Info] = []
internal func active() -> [GPU_Info] {
return self.list.filter{ $0.state }
return self.list.filter{ $0.state && $0.utilization != nil }.sorted{ $0.utilization ?? 0 > $1.utilization ?? 0 }
}
public var widget_value: Double {
get {
return list.isEmpty ? 0 : list[0].utilization
return list.isEmpty ? 0 : (list[0].utilization ?? 0)
}
}
}
@@ -116,16 +131,19 @@ public class GPU: Module {
return
}
let selectedGPU: GPU_Info = activeGPUs.first{ $0.model == self.selectedGPU } ?? activeGPU
guard let utilization = selectedGPU.utilization else {
return
}
if let widget = self.widget as? Mini {
widget.setValue(selectedGPU.utilization)
widget.setValue(utilization)
widget.setTitle(self.showType ? "\(selectedGPU.type)GPU" : nil)
}
if let widget = self.widget as? LineChart {
widget.setValue(selectedGPU.utilization)
widget.setValue(utilization)
}
if let widget = self.widget as? BarChart {
widget.setValue([selectedGPU.utilization])
widget.setValue([utilization])
}
}
}