From 73f976c86bcd8ff7c64d48e71275b30109638ee2 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 1 May 2022 22:22:52 +0200 Subject: [PATCH] gpsautotime: Add setting to hide the widget --- apps/gpsautotime/ChangeLog | 1 + apps/gpsautotime/metadata.json | 8 +++++--- apps/gpsautotime/widget.js | 20 +++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/gpsautotime/ChangeLog b/apps/gpsautotime/ChangeLog index 2827c9e5c..97b80ecdf 100644 --- a/apps/gpsautotime/ChangeLog +++ b/apps/gpsautotime/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Set Bangle.js 2 compatible +0.03: Add setting to hide the widget diff --git a/apps/gpsautotime/metadata.json b/apps/gpsautotime/metadata.json index 766961276..217a27931 100644 --- a/apps/gpsautotime/metadata.json +++ b/apps/gpsautotime/metadata.json @@ -2,13 +2,15 @@ "id": "gpsautotime", "name": "GPS auto time", "shortName": "GPS auto time", - "version": "0.02", + "version": "0.03", "description": "A widget that automatically updates the Bangle.js time to the GPS time whenever there is a valid GPS fix.", "icon": "widget.png", "type": "widget", "tags": "widget,gps", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"gpsautotime.wid.js","url":"widget.js"} - ] + {"name":"gpsautotime.wid.js","url":"widget.js"}, + {"name":"gpsautotime.settings.js","url":"settings.js"} + ], + "data": [{"name":"gpsautotime.json"}] } diff --git a/apps/gpsautotime/widget.js b/apps/gpsautotime/widget.js index a1d1b2b08..a21c14619 100644 --- a/apps/gpsautotime/widget.js +++ b/apps/gpsautotime/widget.js @@ -1,6 +1,13 @@ (() => { var lastTimeSet = 0; + var settings = Object.assign({ + // default values + show: true, + }, require('Storage').readJSON("gpsautotime.json", true) || {}); + const show = settings.show; + delete settings; + Bangle.on('GPS',function(fix) { if (fix.fix) { var curTime = fix.time.getTime()/1000; @@ -14,8 +21,9 @@ // add your widget WIDGETS["gpsAutoTime"]={ area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right) - width: 28, // width of the widget + width: show ? 4*6+2 : 0, // width of the widget draw: function() { + if (!show) return; g.reset(); // reset the graphics context to defaults (color/font/etc) g.setFont("6x8"); if ((getTime() - lastTimeSet) <= 60) { @@ -27,7 +35,9 @@ } }; - setInterval(function() { - WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); - }, 1*60000); // update every minute -})() + if (show) { + setInterval(function() { + WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); + }, 1*60000); // update every minute + } +})();