forked from FOSS/BangleApps
Add new widget alarmeta
This widget displays the time to the next Alarm or Timer in hours and minutes.master
parent
a3a7ef58bf
commit
3900d0a6ad
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "alarmeta",
|
||||
"name": "Alarm & Timer ETA",
|
||||
"shortName": "Alarm ETA",
|
||||
"version": "0.01",
|
||||
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h",
|
||||
"icon": "widget.png",
|
||||
"type": "widget",
|
||||
"tags": "widget",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"screenshots" : [ { "url":"screenshot.png" } ],
|
||||
"storage": [
|
||||
{"name":"alarmeta.wid.js","url":"widget.js"}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1,37 @@
|
|||
(() => {
|
||||
const alarms = require("Storage").readJSON("sched.json",1) || [];
|
||||
|
||||
function draw() {
|
||||
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm)).filter(a => a !== undefined);
|
||||
const next = Math.min.apply(null, times);
|
||||
if (next > 0 && next < 86400000) {
|
||||
const hours = Math.floor((next % 86400000) / 3600000).toString();
|
||||
const minutes = Math.floor(((next % 86400000) % 3600000) / 60000).toString();
|
||||
|
||||
g.reset(); // reset the graphics context to defaults (color/font/etc)
|
||||
g.setFontAlign(0,0); // center fonts
|
||||
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
|
||||
|
||||
// Use 'locale' module to get a shortened month name
|
||||
// in the correct language
|
||||
var text = hours.padStart(2, '0') + ":" + minutes.padStart(2, '0');
|
||||
g.setFont("6x8:1x2");
|
||||
g.drawString(text, this.x+this.width/2, this.y+12);
|
||||
if (this.width === 0) {
|
||||
this.width = 6*5+2;
|
||||
Bangle.drawWidgets(); // width changed, re-layout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
WIDGETS["alarmeta"].draw(WIDGETS["alarmeta"]);
|
||||
}, 30000); // update every half minute
|
||||
|
||||
// add your widget
|
||||
WIDGETS["alarmeta"]={
|
||||
area:"tl",
|
||||
width: 0, // hide by default = assume no timer
|
||||
draw:draw
|
||||
};
|
||||
})();
|
Binary file not shown.
After Width: | Height: | Size: 1011 B |
Loading…
Reference in New Issue