From f15fd9cf203986f53af6bb63fe41e58915d4d6ad Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 5 Jun 2023 19:16:29 -0600 Subject: [PATCH] Fetch grid on load --- antonclk/antonclk.app.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/antonclk/antonclk.app.js b/antonclk/antonclk.app.js index e7fb490..5a190cd 100644 --- a/antonclk/antonclk.app.js +++ b/antonclk/antonclk.app.js @@ -58,16 +58,6 @@ Graphics.prototype.setFontAnton = function(scale) { }); } - if (Bangle.http && !grid){ - Bangle.http("https://api.home.dns.t0.vc/grid", {timeout:3000}).then(event => { - grid = JSON.parse(event.resp); - //console.log(grid); - }).catch((e)=>{ - myMessage = "GET error"; - if (paintFace) paintFace(); - }); - } - // queue next draw if (drawTimer) clearTimeout(drawTimer); drawTimer = setTimeout(function() { @@ -168,10 +158,13 @@ Graphics.prototype.setFontAnton = function(scale) { }, 2000); if (gridNum >= 0 && grid[gridNum]) { + myMessage = grid[gridNum]; + if (paintFace) paintFace(); + if (Bangle.http){ const options = {timeout:3000, method: "post", body: gridNum}; Bangle.http("https://api.home.dns.t0.vc/grid", options).then(event => { - myMessage = grid[gridNum]; + myMessage = "ok" if (paintFace) paintFace(); }).catch((e)=>{ myMessage = "POST error"; @@ -187,6 +180,16 @@ Graphics.prototype.setFontAnton = function(scale) { } }; + if (Bangle.http){ + Bangle.http("https://api.home.dns.t0.vc/grid", {timeout:3000}).then(event => { + grid = JSON.parse(event.resp); + //console.log(grid); + }).catch((e)=>{ + myMessage = "GET error"; + if (paintFace) paintFace(); + }); + } + Bangle.on('swipe', handleSwipe); Bangle.on('drag', handleDrag);