mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
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:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user