added strikethrough for old values

pull/2577/head
Phil Roggenbuck 2023-02-14 21:40:16 +01:00 committed by GitHub
parent 9c005ca4b8
commit 9eec5c6028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 21 deletions

View File

@ -6,33 +6,34 @@
let settings; let settings;
function loadSettings() { // stolen from https://github.com/espruino/BangleApps/blob/master/apps/widpedom/widget.js function loadSettings() { // stolen from https://github.com/espruino/BangleApps/blob/master/apps/widpedom/widget.js
try { try {
const d = require('Storage').readJSON("widbgjs.settings.json", 1) || {}; const d = require('Storage').readJSON("widbgjs.settings.json", 1) || {};
settings = Object.assign({ settings = Object.assign({
'unitIsMmol': true, 'unitIsMmol': true,
'expireThreshold': 600000, 'expireThreshold': 600000,
'reloadInterval': 300000, //'reloadInterval': 300000, // 2add in the future
'hide': false 'hide': false
}, d || {}); }, d || {});
return d; return d;
} catch(e){ } catch(e){
return null; //console.log(e.toString());
} return;
}
} }
function loadVals() { function loadVals() {
try { try {
const d = require('Storage').readJSON("widbgjs.json", 1) || {}; const d = require('Storage').readJSON("widbgjs.json", 1) || {};
storedData = Object.assign({ storedData = Object.assign({
'bg': null, 'bg': 100,
'bgTimeStamp': null, 'bgTimeStamp': null,
'bgDirection': null 'bgDirection': "Flat"
}, d || {}); }, d || {});
return d; return d;
} catch(e) { } catch(e) {
Bangle.removeFile("widbgjs.json"); Bangle.removeFile("widbgjs.json");
} }
return null; return;
} }
function calculateRotation(bgDirection) { function calculateRotation(bgDirection) {
@ -108,8 +109,9 @@ return null;
function draw() { function draw() {
loadSettings(); loadSettings();
if(settings.hide) { if(settings.hide) {
return; return;
} }
console.log(settings.unitIsMmol.toString());
loadVals(); loadVals();
outpt = getBG(storedData.bg); outpt = getBG(storedData.bg);
@ -124,16 +126,19 @@ return;
g.setFont('Vector', 22); g.setFont('Vector', 22);
g.setColor(g.theme.fg); g.setColor(g.theme.fg);
// check if the value is too old // if the value is too old strikethrough it
if (!isBgTooOld(storedData.bgTimeStamp)) { if (isBgTooOld(storedData.bgTimeStamp)) {
g.drawImage(atob("FBQBAGAADwAB+AA/wAduAGZgAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgAAYAAGAABgA="), this.x + 60, this.y + 9, { rotate: calculateRotation(storedData.bgDirection) }); 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); g.setColor(g.theme.fg).drawString(outpt, this.x + 5, this.y);
} }
setInterval(function () { setInterval(function () {
WIDGETS["widbgjs"].draw(WIDGETS["widbgjs"]); WIDGETS["widbgjs"].draw(WIDGETS["widbgjs"]);
}, 5 * 60000); // update every 5 minutes (%* 60000 }, 5 * 60000); // update every 5 minutes (5 * 60000)
// add your widget // add your widget