widalarmeta: Fix when no alarms are present
parent
625e52514d
commit
a3addeebb2
|
|
@ -8,3 +8,4 @@
|
|||
0.05: Convert Yes/No On/Off in settings to checkboxes
|
||||
0.06: Remember next alarm to reduce calculation amount
|
||||
Redraw only every hour when no alarm in next 24h
|
||||
0.07: Fix when no alarms are present
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "widalarmeta",
|
||||
"name": "Alarm & Timer ETA",
|
||||
"shortName": "Alarm ETA",
|
||||
"version": "0.06",
|
||||
"version": "0.07",
|
||||
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).",
|
||||
"icon": "widget.png",
|
||||
"type": "widget",
|
||||
|
|
|
|||
|
|
@ -9,14 +9,16 @@
|
|||
function getNextAlarm(date) {
|
||||
const alarms = (require("Storage").readJSON("sched.json",1) || []).filter(alarm => alarm.on && alarm.hidden !== true);
|
||||
WIDGETS["widalarmeta"].numActiveAlarms = alarms.length;
|
||||
if (alarms.length > 0) {
|
||||
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm, date) || Number.POSITIVE_INFINITY);
|
||||
const eta = times.length > 0 ? Math.min.apply(null, times) : 0;
|
||||
const eta = Math.min.apply(null, times);
|
||||
if (eta !== Number.POSITIVE_INFINITY) {
|
||||
const idx = times.indexOf(eta);
|
||||
const alarm = alarms[idx];
|
||||
delete alarm.msg; delete alarm.id; delete alarm.data; // free some memory
|
||||
return alarm;
|
||||
}
|
||||
}
|
||||
} // getNextAlarm
|
||||
|
||||
function draw(fromInterval) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue