1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Bangle.js: if music state is out of range, just return '' (fix #2485)

This commit is contained in:
Gordon Williams 2021-12-09 16:09:49 +00:00
parent 4981aacb30
commit e82662f0bf

View File

@ -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);