mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added option to disable SMART reads (#2294)
This commit is contained in:
@@ -35,6 +35,10 @@ let kIOCFPlugInInterfaceID = CFUUIDGetConstantUUIDWithBytes(nil,
|
||||
internal class CapacityReader: Reader<Disks> {
|
||||
internal var list: Disks = Disks()
|
||||
|
||||
private var SMART: Bool {
|
||||
Store.shared.bool(key: "\(ModuleType.disk.rawValue)_SMART", defaultValue: true)
|
||||
}
|
||||
|
||||
public override func read() {
|
||||
let keys: [URLResourceKey] = [.volumeNameKey]
|
||||
let removableState = Store.shared.bool(key: "Disk_removable", defaultValue: false)
|
||||
@@ -129,6 +133,8 @@ internal class CapacityReader: Reader<Disks> {
|
||||
}
|
||||
|
||||
private func getSMARTDetails(for BSDName: String) -> smart_t? {
|
||||
guard self.SMART else { return nil }
|
||||
|
||||
var disk = IOServiceGetMatchingService(kIOMasterPortDefault, IOBSDNameMatching(kIOMasterPortDefault, 0, BSDName.cString(using: .utf8)))
|
||||
guard disk != kIOReturnSuccess else { return nil }
|
||||
defer { IOObjectRelease(disk) }
|
||||
|
||||
@@ -19,6 +19,7 @@ internal class Settings: NSStackView, Settings_v {
|
||||
private var updateIntervalValue: Int = 10
|
||||
private var numberOfProcesses: Int = 5
|
||||
private var baseValue: String = "byte"
|
||||
private var SMARTState: Bool = true
|
||||
|
||||
public var selectedDiskHandler: (String) -> Void = {_ in }
|
||||
public var callback: (() -> Void) = {}
|
||||
@@ -38,6 +39,7 @@ internal class Settings: NSStackView, Settings_v {
|
||||
self.updateIntervalValue = Store.shared.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
|
||||
self.numberOfProcesses = Store.shared.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
self.baseValue = Store.shared.string(key: "\(self.title)_base", defaultValue: self.baseValue)
|
||||
self.SMARTState = Store.shared.bool(key: "\(self.title)_SMART", defaultValue: self.SMARTState)
|
||||
|
||||
super.init(frame: NSRect.zero)
|
||||
|
||||
@@ -90,6 +92,13 @@ internal class Settings: NSStackView, Settings_v {
|
||||
))
|
||||
]))
|
||||
}
|
||||
|
||||
self.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("SMART data"), component: switchView(
|
||||
action: #selector(self.toggleSMART),
|
||||
state: self.SMARTState
|
||||
))
|
||||
]))
|
||||
}
|
||||
|
||||
internal func setList(_ list: Disks) {
|
||||
@@ -143,4 +152,9 @@ internal class Settings: NSStackView, Settings_v {
|
||||
self.baseValue = key
|
||||
Store.shared.set(key: "\(self.title)_base", value: self.baseValue)
|
||||
}
|
||||
@objc private func toggleSMART(_ sender: NSControl) {
|
||||
self.SMARTState = controlState(sender)
|
||||
Store.shared.set(key: "\(self.title)_SMART", value: self.SMARTState)
|
||||
self.callback()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user