1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30
yattee/macOS/Power.swift

39 lines
1.3 KiB
Swift
Raw Normal View History

2022-08-14 22:36:22 +05:30
import Foundation
2024-02-02 04:21:41 +05:30
enum Power {
2022-08-14 22:36:22 +05:30
static var hasInternalBattery: Bool {
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
for ps in psList {
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
if let type = psDesc[kIOPSTypeKey] as? String,
type == kIOPSInternalBatteryType
{
return true
2022-08-14 22:36:22 +05:30
}
}
}
return false
}
static var isConnectedToPower: Bool {
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
for ps in psList {
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
if let type = psDesc[kIOPSTypeKey] as? String,
type == kIOPSInternalBatteryType,
2022-08-14 22:36:22 +05:30
let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String)
{
return powerSourceState == kIOPSACPowerValue
}
}
}
return false
}
}