gpsautotime: Add setting to hide the widget

pull/1782/head
Erik Andresen 2022-05-01 22:22:52 +02:00
parent 2a0cf8e44e
commit 73f976c86b
3 changed files with 21 additions and 8 deletions

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Set Bangle.js 2 compatible
0.03: Add setting to hide the widget

View File

@ -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"}]
}

View File

@ -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
}
})();