Skip to content

Commit

Permalink
fix(battery_plus): handle empty power sources array
Browse files Browse the repository at this point in the history
  • Loading branch information
xioxin authored Aug 8, 2024
1 parent 5084333 commit 1bbbd5c
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class BatteryPlusMacosPlugin: NSObject, FlutterPlugin {
private func getBatteryLevel()-> Int {
let powerSourceSnapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue()
let sources = IOPSCopyPowerSourcesList(powerSourceSnapshot).takeRetainedValue() as Array
if sources.isEmpty {
return -1
}
let description = IOPSGetPowerSourceDescription(powerSourceSnapshot, sources[0]).takeUnretainedValue() as! [String: AnyObject]
if let currentCapacity = description[kIOPSCurrentCapacityKey] as? Int {
return currentCapacity;
Expand Down

0 comments on commit 1bbbd5c

Please sign in to comment.