mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added an option to select fan value for widget: rpm or percentage (#1236)
This commit is contained in:
@@ -33,6 +33,7 @@ identifier_name:
|
||||
- _devices
|
||||
- _uuidAddress
|
||||
- AppleSiliconSensorsList
|
||||
- FanValues
|
||||
|
||||
line_length: 200
|
||||
|
||||
|
||||
@@ -277,3 +277,12 @@ extension Scale: CaseIterable {
|
||||
return Scale.allCases.first{ $0.key == key } ?? defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
public enum FanValue: String {
|
||||
case rpm
|
||||
case percentage
|
||||
}
|
||||
public let FanValues: [KeyValue_t] = [
|
||||
KeyValue_t(key: "rpm", value: "RPM", additional: FanValue.rpm),
|
||||
KeyValue_t(key: "percentage", value: "Percentage", additional: FanValue.percentage)
|
||||
]
|
||||
|
||||
@@ -17,6 +17,10 @@ public class Sensors: Module {
|
||||
private let popupView: Popup = Popup()
|
||||
private var settingsView: Settings
|
||||
|
||||
private var fanValueState: FanValue {
|
||||
FanValue(rawValue: Store.shared.string(key: "\(self.config.name)_fanValue", defaultValue: "percentage")) ?? .percentage
|
||||
}
|
||||
|
||||
public init() {
|
||||
self.sensorsReader = SensorsReader()
|
||||
self.settingsView = Settings("Sensors", list: self.sensorsReader.list)
|
||||
@@ -102,10 +106,14 @@ public class Sensors: Module {
|
||||
|
||||
value.forEach { (s: Sensor_p) in
|
||||
if s.state {
|
||||
list.append(KeyValue_t(key: s.key, value: s.formattedMiniValue, additional: s.name))
|
||||
var value = s.formattedMiniValue
|
||||
if let f = s as? Fan {
|
||||
flatList.append([ColorValue(((f.value*100)/f.maxSpeed)/100)])
|
||||
if self.fanValueState == .percentage {
|
||||
value = "\(f.percentage)%"
|
||||
}
|
||||
}
|
||||
list.append(KeyValue_t(key: s.key, value: value, additional: s.name))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -421,16 +421,11 @@ internal class FanView: NSStackView {
|
||||
nameField.cell?.truncatesLastVisibleLine = true
|
||||
|
||||
let value = self.fan.value
|
||||
var percentage = ""
|
||||
if value != 1 && self.fan.maxSpeed != 1 {
|
||||
percentage = "\((100*Int(value)) / Int(self.fan.maxSpeed))%"
|
||||
}
|
||||
|
||||
let valueField: NSTextField = TextView()
|
||||
valueField.font = NSFont.systemFont(ofSize: 13, weight: .regular)
|
||||
valueField.stringValue = self.fan.formattedValue
|
||||
valueField.alignment = .right
|
||||
valueField.stringValue = percentage
|
||||
valueField.stringValue = "\(self.fan.percentage)%"
|
||||
valueField.toolTip = "\(value)"
|
||||
|
||||
row.addArrangedSubview(nameField)
|
||||
@@ -700,7 +695,7 @@ internal class FanView: NSStackView {
|
||||
if self.fan.maxSpeed == 1 || self.fan.maxSpeed == 0 {
|
||||
speed = "\(Int(value.value)) RPM"
|
||||
} else {
|
||||
speed = "\((100*Int(value.value)) / Int(self.fan.maxSpeed))%"
|
||||
speed = "\(value.percentage)%"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ internal class Settings: NSStackView, Settings_v {
|
||||
private var fanSpeedState: Bool = false
|
||||
private var fansSyncState: Bool = false
|
||||
private var unknownSensorsState: Bool = false
|
||||
private var fanValueState: FanValue = .percentage
|
||||
|
||||
private let title: String
|
||||
private var button: NSPopUpButton?
|
||||
@@ -52,6 +53,7 @@ internal class Settings: NSStackView, Settings_v {
|
||||
self.fanSpeedState = Store.shared.bool(key: "\(self.title)_speed", defaultValue: self.fanSpeedState)
|
||||
self.fansSyncState = Store.shared.bool(key: "\(self.title)_fansSync", defaultValue: self.fansSyncState)
|
||||
self.unknownSensorsState = Store.shared.bool(key: "\(self.title)_unknown", defaultValue: self.unknownSensorsState)
|
||||
self.fanValueState = FanValue(rawValue: Store.shared.string(key: "\(self.title)_fanValue", defaultValue: self.fanValueState.rawValue)) ?? .percentage
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -83,6 +85,13 @@ internal class Settings: NSStackView, Settings_v {
|
||||
state: self.fansSyncState
|
||||
))
|
||||
|
||||
self.addArrangedSubview(selectSettingsRow(
|
||||
title: localizedString("Fan value"),
|
||||
action: #selector(toggleFanValue),
|
||||
items: FanValues,
|
||||
selected: self.fanValueState.rawValue
|
||||
))
|
||||
|
||||
if isARM {
|
||||
self.addArrangedSubview(toggleSettingRow(
|
||||
title: localizedString("HID sensors"),
|
||||
@@ -197,4 +206,12 @@ internal class Settings: NSStackView, Settings_v {
|
||||
Store.shared.set(key: "\(self.title)_unknown", value: self.unknownSensorsState)
|
||||
self.unknownCallback()
|
||||
}
|
||||
|
||||
@objc func toggleFanValue(_ sender: NSMenuItem) {
|
||||
if let key = sender.representedObject as? String, let value = FanValue(rawValue: key) {
|
||||
self.fanValueState = value
|
||||
Store.shared.set(key: "\(self.title)_fanValue", value: self.fanValueState.rawValue)
|
||||
self.callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,13 @@ internal struct Fan: Sensor_p {
|
||||
var value: Double
|
||||
var mode: FanMode
|
||||
|
||||
var percentage: Int {
|
||||
if self.value != 0 && self.maxSpeed != 0 && self.value != 1 && self.maxSpeed != 1 {
|
||||
return (100*Int(self.value)) / Int(self.maxSpeed)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var group: SensorGroup = .sensor
|
||||
var type: SensorType = .fan
|
||||
var platforms: [Platform] = Platform.all
|
||||
|
||||
Reference in New Issue
Block a user