Retry logic for sending intents

pull/1995/head
David Peer 2022-06-24 12:45:11 +02:00
parent 649ecf4952
commit c0f3d9b8a9
1 changed files with 26 additions and 16 deletions

View File

@ -46,6 +46,29 @@ try{
}
function sendIntent(trigger){
var retries=3;
while(retries > 0){
try{
// Send a startup trigger such that we could also execute
// an action when the app is started :)
Bluetooth.println(JSON.stringify({
t:"intent",
action:"com.espruino.gadgetbridge.banglejs.HA",
extra:{
trigger: trigger
}})
);
retries = -1;
} catch(e){
retries--;
}
}
}
function draw() {
g.reset().clearRect(Bangle.appRect);
@ -88,13 +111,7 @@ Bangle.on('touch', function(btn, e){
if(!isRight && !isLeft){
Bangle.buzz(80, 0.6).then(()=>{
Bluetooth.println(JSON.stringify({
t:"intent",
action:"com.espruino.gadgetbridge.banglejs.HA",
extra:{
trigger: triggers[position].trigger
}})
);
sendIntent(triggers[position].trigger);
setTimeout(()=>{
Bangle.buzz(80, 0.6);
}, 250);
@ -104,15 +121,8 @@ Bangle.on('touch', function(btn, e){
draw();
});
// Send a startup trigger such that we could also execute
// an action when the app is started :)
Bluetooth.println(JSON.stringify({
t:"intent",
action:"com.espruino.gadgetbridge.banglejs.HA",
extra:{
trigger: "APP_STARTED"
}})
);
// Send intent that the we started the app.
sendIntent("APP_STARTED");
// Next load the widgets and draw the app
Bangle.loadWidgets();