mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Add function to determine if the computer has battery
Also the default value for the "showBatteryIndicator" is the result of the function: if the device is a MacBook it defaults to true like before, otherwise to false
This commit is contained in:
parent
4f36b69abf
commit
acb6cd8470
2 changed files with 9 additions and 1 deletions
|
|
@ -304,6 +304,14 @@ class BatteryActivityManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determines if the device has a battery
|
||||||
|
/// - Returns: True if the computer has a battery, false otherwhise
|
||||||
|
func hasBattery() -> Bool {
|
||||||
|
guard let snapshot = IOPSCopyPowerSourcesInfo()?.takeRetainedValue() else { return false }
|
||||||
|
guard let sources = IOPSCopyPowerSourcesList(snapshot)?.takeRetainedValue() as? [CFTypeRef] else { return false }
|
||||||
|
return !sources.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
stopMonitoring()
|
stopMonitoring()
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
|
|
||||||
|
|
@ -479,7 +479,7 @@ extension Defaults.Keys {
|
||||||
|
|
||||||
// MARK: Battery
|
// MARK: Battery
|
||||||
static let showPowerStatusNotifications = Key<Bool>("showPowerStatusNotifications", default: true)
|
static let showPowerStatusNotifications = Key<Bool>("showPowerStatusNotifications", default: true)
|
||||||
static let showBatteryIndicator = Key<Bool>("showBatteryIndicator", default: true)
|
static let showBatteryIndicator = Key<Bool>("showBatteryIndicator", default: BatteryActivityManager.shared.hasBattery())
|
||||||
static let showBatteryPercentage = Key<Bool>("showBatteryPercentage", default: true)
|
static let showBatteryPercentage = Key<Bool>("showBatteryPercentage", default: true)
|
||||||
static let showPowerStatusIcons = Key<Bool>("showPowerStatusIcons", default: true)
|
static let showPowerStatusIcons = Key<Bool>("showPowerStatusIcons", default: true)
|
||||||
static let playLowBatteryAlertSound = Key<Bool>("playLowBatteryAlertSound", default: true)
|
static let playLowBatteryAlertSound = Key<Bool>("playLowBatteryAlertSound", default: true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue