feat: added an option to enable/disable HID sensors for mac with Apple Silicon (disabled by default)

feat: added option to save fan speed to the Sensors module
This commit is contained in:
Serhiy Mytrovtsiy
2022-01-14 20:34:39 +01:00
parent da08c0f1fc
commit 98ee87fbf8
3 changed files with 109 additions and 44 deletions

View File

@@ -14,11 +14,14 @@ import Kit
internal class Settings: NSStackView, Settings_v {
private var updateIntervalValue: Int = 3
private var hidState: Bool = false
private var fanSpeedState: Bool = false
private let title: String
private var button: NSPopUpButton?
private let list: [Sensor_p]
public var callback: (() -> Void) = {}
public var HIDcallback: (() -> Void) = {}
public var setInterval: ((_ value: Int) -> Void) = {_ in }
public init(_ title: String, list: [Sensor_p]) {
@@ -40,6 +43,8 @@ internal class Settings: NSStackView, Settings_v {
self.spacing = Constants.Settings.margin
self.updateIntervalValue = Store.shared.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
self.hidState = Store.shared.bool(key: "\(self.title)_hid", defaultValue: self.hidState)
self.fanSpeedState = Store.shared.bool(key: "\(self.title)_speed", defaultValue: self.fanSpeedState)
}
required init?(coder: NSCoder) {
@@ -66,6 +71,18 @@ internal class Settings: NSStackView, Settings_v {
selected: "\(self.updateIntervalValue) sec"
))
self.addArrangedSubview(toggleSettingRow(
title: localizedString("Save the fan speed"),
action: #selector(toggleSpeedState),
state: self.fanSpeedState
))
self.addArrangedSubview(toggleSettingRow(
title: localizedString("HID sensors"),
action: #selector(toggleHID),
state: self.hidState
))
types.forEach { (typ: SensorType) in
let header = NSStackView()
header.heightAnchor.constraint(equalToConstant: Constants.Settings.row).isActive = true
@@ -137,4 +154,30 @@ internal class Settings: NSStackView, Settings_v {
self.setInterval(value)
}
}
@objc private func toggleSpeedState(_ sender: NSControl) {
var state: NSControl.StateValue? = nil
if #available(OSX 10.15, *) {
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
} else {
state = sender is NSButton ? (sender as! NSButton).state: nil
}
self.fanSpeedState = state! == .on ? true : false
Store.shared.set(key: "\(self.title)_speed", value: self.fanSpeedState)
self.callback()
}
@objc func toggleHID(_ sender: NSControl) {
var state: NSControl.StateValue? = nil
if #available(OSX 10.15, *) {
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
} else {
state = sender is NSButton ? (sender as! NSButton).state: nil
}
self.hidState = state! == .on ? true : false
Store.shared.set(key: "\(self.title)_hid", value: self.hidState)
self.HIDcallback()
}
}