BangleApps/apps/gpsautotime/widget.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-22 18:48:08 +00:00
(() => {
var lastTimeSet = 0;
var settings = Object.assign({
// default values
show: true,
}, require('Storage').readJSON("gpsautotime.json", true) || {});
const show = settings.show;
delete settings;
2020-06-22 18:48:08 +00:00
Bangle.on('GPS',function(fix) {
if (fix.fix && fix.time) {
2020-06-22 18:48:08 +00:00
var curTime = fix.time.getTime()/1000;
setTime(curTime);
lastTimeSet = curTime;
WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]);
}
});
// add your widget
WIDGETS["gpsAutoTime"]={
area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right)
width: show ? 4*6+2 : 0, // width of the widget
2020-06-22 18:48:08 +00:00
draw: function() {
if (!show) return;
2020-06-22 18:48:08 +00:00
g.reset(); // reset the graphics context to defaults (color/font/etc)
g.setFont("6x8");
if ((getTime() - lastTimeSet) <= 60) {
// time is uptodate
g.setColor('#00ff00'); // green
}
g.drawString("auto", this.x, this.y);
g.drawString("time", this.x, this.y+10);
}
};
if (show) {
setInterval(function() {
WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]);
}, 1*60000); // update every minute
}
})();