diff --git a/src/main/java/org/myrobotlab/service/Runtime.java b/src/main/java/org/myrobotlab/service/Runtime.java index 79439eea08..2185727eb5 100644 --- a/src/main/java/org/myrobotlab/service/Runtime.java +++ b/src/main/java/org/myrobotlab/service/Runtime.java @@ -3687,23 +3687,21 @@ public static Double getBatteryLevel() { // TODO This is incorrect, will not work when unplugged // and acpitool output is different than expected, // at least on Ubuntu 22.04 - consider oshi library - if (FileIO.isExecutableAvailable("acpi")) { - String ret = Runtime.execute("acpi"); - int pos0 = ret.indexOf("%"); - - if (pos0 != -1) { - int pos1 = ret.lastIndexOf(" ", pos0); - // int pos1 = ret.indexOf("%", pos0); - String dble = ret.substring(pos1, pos0).trim(); - try { - r = Double.parseDouble(dble); - } catch (Exception e) { - log.error("no Battery detected by system"); - } - return r; + String ret = Runtime.execute("acpi"); + int pos0 = ret.indexOf("%"); + + if (pos0 != -1) { + int pos1 = ret.lastIndexOf(" ", pos0); + // int pos1 = ret.indexOf("%", pos0); + String dble = ret.substring(pos1, pos0).trim(); + try { + r = Double.parseDouble(dble); + } catch (Exception e) { + log.error("no Battery detected by system"); } - log.info(ret); + return r; } + log.info(ret); } else if (platform.isMac()) { String ret = Runtime.execute("pmset -g batt"); int pos0 = ret.indexOf("Battery-0");