From 9eec5c6028a33e3af0f002d88edc26e609a2650e Mon Sep 17 00:00:00 2001 From: Phil Roggenbuck <1367949+phrogg@users.noreply.github.com> Date: Tue, 14 Feb 2023 21:40:16 +0100 Subject: [PATCH] added strikethrough for old values --- apps/widbgjs/widget.js | 47 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/widbgjs/widget.js b/apps/widbgjs/widget.js index f318dcfcc..8418f3e9f 100644 --- a/apps/widbgjs/widget.js +++ b/apps/widbgjs/widget.js @@ -6,33 +6,34 @@ let settings; function loadSettings() { // stolen from https://github.com/espruino/BangleApps/blob/master/apps/widpedom/widget.js -try { - const d = require('Storage').readJSON("widbgjs.settings.json", 1) || {}; - settings = Object.assign({ - 'unitIsMmol': true, - 'expireThreshold': 600000, - 'reloadInterval': 300000, - 'hide': false - }, d || {}); - return d; -} catch(e){ -return null; -} + try { + const d = require('Storage').readJSON("widbgjs.settings.json", 1) || {}; + settings = Object.assign({ + 'unitIsMmol': true, + 'expireThreshold': 600000, + //'reloadInterval': 300000, // 2add in the future + 'hide': false + }, d || {}); + return d; + } catch(e){ + //console.log(e.toString()); + return; + } } function loadVals() { try { const d = require('Storage').readJSON("widbgjs.json", 1) || {}; storedData = Object.assign({ - 'bg': null, + 'bg': 100, 'bgTimeStamp': null, - 'bgDirection': null + 'bgDirection': "Flat" }, d || {}); return d; } catch(e) { Bangle.removeFile("widbgjs.json"); } - return null; + return; } function calculateRotation(bgDirection) { @@ -108,8 +109,9 @@ return null; function draw() { loadSettings(); if(settings.hide) { -return; -} + return; + } + console.log(settings.unitIsMmol.toString()); loadVals(); outpt = getBG(storedData.bg); @@ -124,16 +126,19 @@ return; g.setFont('Vector', 22); g.setColor(g.theme.fg); - // check if the value is too old - if (!isBgTooOld(storedData.bgTimeStamp)) { - g.drawImage(atob("FBQBAGAADwAB+AA/wAduAGZgAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgA="), this.x + 60, this.y + 9, { rotate: calculateRotation(storedData.bgDirection) }); + // if the value is too old strikethrough it + if (isBgTooOld(storedData.bgTimeStamp)) { + g.fillRect(this.x + 5, this.y + 9, g.stringWidth(outpt),this.y + 10); } + + g.drawImage(atob("FBQBAGAADwAB+AA/wAduAGZgAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgA="), this.x + 60, this.y + 9, { rotate: calculateRotation(storedData.bgDirection)}); g.setColor(g.theme.fg).drawString(outpt, this.x + 5, this.y); + } setInterval(function () { WIDGETS["widbgjs"].draw(WIDGETS["widbgjs"]); - }, 5 * 60000); // update every 5 minutes (%* 60000 + }, 5 * 60000); // update every 5 minutes (5 * 60000) // add your widget