From e82662f0bf420e395f14b70e818fe5af23be4578 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 9 Dec 2021 16:09:49 +0000 Subject: [PATCH] Bangle.js: if music state is out of range, just return '' (fix #2485) --- .../service/devices/banglejs/BangleJSDeviceSupport.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java index f0ab98246..fd164dd01 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java @@ -153,7 +153,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { private void handleUartRxLine(String line) { LOG.info("UART RX LINE: " + line); - if (">Uncaught ReferenceError: \"gb\" is not defined".equals(line)) + if (">Uncaught ReferenceError: \"GB\" is not defined".equals(line)) GB.toast(getContext(), "Gadgetbridge plugin not installed on Bangle.js", Toast.LENGTH_LONG, GB.ERROR); else if (line.charAt(0)=='{') { // JSON - we hope! @@ -412,8 +412,11 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { try { JSONObject o = new JSONObject(); o.put("t", "musicstate"); + int musicState = stateSpec.state; String[] musicStates = {"play", "pause", "stop", ""}; - o.put("state", musicStates[stateSpec.state]); + if (musicState<0) musicState=3; + if (musicState>=musicStates.length) musicState = musicStates.length-1; + o.put("state", musicStates[musicState]); o.put("position", stateSpec.position); o.put("shuffle", stateSpec.shuffle); o.put("repeat", stateSpec.repeat);