Skip to content

Commit

Permalink
fix(ios): Check for null on GCController.battery (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berstanio authored Oct 21, 2023
1 parent 94636b5 commit 29ddbc0
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.robovm.apple.gamecontroller.GCControllerDirectionPad;
import org.robovm.apple.gamecontroller.GCControllerElement;
import org.robovm.apple.gamecontroller.GCControllerPlayerIndex;
import org.robovm.apple.gamecontroller.GCDeviceBattery;
import org.robovm.apple.gamecontroller.GCExtendedGamepad;
import org.robovm.apple.gamecontroller.GCGamepad;
import org.robovm.apple.gamecontroller.GCHapticsLocality;
Expand Down Expand Up @@ -415,9 +416,13 @@ public ControllerMapping getMapping() {
@Override
public ControllerPowerLevel getPowerLevel() {
if (Foundation.getMajorSystemVersion() >= 14) {
switch (controller.getBattery().getBatteryState()) {
GCDeviceBattery battery = controller.getBattery();
if (battery == null)
return ControllerPowerLevel.POWER_UNKNOWN;

switch (battery.getBatteryState()) {
case Discharging:
float batteryLevel = controller.getBattery().getBatteryLevel();
float batteryLevel = battery.getBatteryLevel();
if (batteryLevel <= 0.05f) {
return ControllerPowerLevel.POWER_EMPTY;
} else if (batteryLevel <= 0.20f) {
Expand Down

0 comments on commit 29ddbc0

Please sign in to comment.