Use system constant for internal battery power source name on macOS

This commit is contained in:
Arkadiusz Fal 2022-08-15 00:20:27 +02:00
parent c5738ee14a
commit 561ead0c5a

View File

@ -7,13 +7,13 @@ struct Power {
for ps in psList { for ps in psList {
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] { if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
if let type = psDesc[kIOPSTypeKey] as? String { if let type = psDesc[kIOPSTypeKey] as? String,
if type == "InternalBattery" { type == kIOPSInternalBatteryType
{
return true return true
} }
} }
} }
}
return false return false
} }
@ -25,7 +25,7 @@ struct Power {
for ps in psList { for ps in psList {
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] { if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
if let type = psDesc[kIOPSTypeKey] as? String, if let type = psDesc[kIOPSTypeKey] as? String,
type == "InternalBattery", type == kIOPSInternalBatteryType,
let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String) let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String)
{ {
return powerSourceState == kIOPSACPowerValue return powerSourceState == kIOPSACPowerValue