2022-08-11 11:07:28 +00:00
|
|
|
(function() {
|
|
|
|
const alarm = require('sched');
|
|
|
|
const iconAlarmOn = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/n+B/n+B/h+B/4+A/+8A//8Af/4AP/wAH/gAB+AAAAAAAAAA==");
|
2022-11-25 07:59:07 +00:00
|
|
|
const iconAlarmOff = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA==");
|
|
|
|
const iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA==");
|
|
|
|
const iconTimerOff = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA==");
|
2022-08-11 11:07:28 +00:00
|
|
|
|
|
|
|
//from 0 to max, the higher the closer to fire (as in a progress bar)
|
|
|
|
function getAlarmValue(a){
|
|
|
|
let min = Math.round(alarm.getTimeToAlarm(a)/(60*1000));
|
|
|
|
if(!min) return 0; //not active or more than a day
|
|
|
|
return getAlarmMax(a)-min;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAlarmMax(a) {
|
|
|
|
if(a.timer)
|
|
|
|
return Math.round(a.timer/(60*1000));
|
|
|
|
//minutes cannot be more than a full day
|
|
|
|
return 1440;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAlarmIcon(a) {
|
|
|
|
if(a.on) {
|
|
|
|
if(a.timer) return iconTimerOn;
|
|
|
|
return iconAlarmOn;
|
|
|
|
} else {
|
|
|
|
if(a.timer) return iconTimerOff;
|
|
|
|
return iconAlarmOff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAlarmText(a){
|
|
|
|
if(a.timer) {
|
2022-12-01 20:03:15 +00:00
|
|
|
if(!a.on) return /*LANG*/"off";
|
2022-08-11 11:07:28 +00:00
|
|
|
let time = Math.round(alarm.getTimeToAlarm(a)/(60*1000));
|
|
|
|
if(time > 60)
|
|
|
|
time = Math.round(time / 60) + "h";
|
|
|
|
else
|
|
|
|
time += "m";
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
return require("time_utils").formatTime(a.t);
|
|
|
|
}
|
|
|
|
|
2022-11-25 07:59:07 +00:00
|
|
|
//workaround for sorting undefined values
|
|
|
|
function getAlarmOrder(a) {
|
|
|
|
let val = alarm.getTimeToAlarm(a);
|
|
|
|
if(typeof val == "undefined") return 86400*1000;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:07:28 +00:00
|
|
|
var img = iconAlarmOn;
|
|
|
|
//get only alarms not created by other apps
|
|
|
|
var alarmItems = {
|
2022-12-01 20:03:15 +00:00
|
|
|
name: /*LANG*/"Alarms",
|
2022-08-11 11:07:28 +00:00
|
|
|
img: img,
|
2022-11-25 17:28:20 +00:00
|
|
|
dynamic: true,
|
2022-08-11 11:07:28 +00:00
|
|
|
items: alarm.getAlarms().filter(a=>!a.appid)
|
2022-11-25 07:59:07 +00:00
|
|
|
//.sort((a,b)=>alarm.getTimeToAlarm(a)-alarm.getTimeToAlarm(b))
|
|
|
|
.sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b))
|
2022-08-11 11:07:28 +00:00
|
|
|
.map((a, i)=>({
|
|
|
|
name: null,
|
2022-11-25 17:28:20 +00:00
|
|
|
hasRange: true,
|
2022-08-11 11:07:28 +00:00
|
|
|
get: () => ({ text: getAlarmText(a), img: getAlarmIcon(a),
|
2022-11-25 17:28:20 +00:00
|
|
|
v: getAlarmValue(a), min:0, max:getAlarmMax(a)}),
|
2022-08-11 11:07:28 +00:00
|
|
|
show: function() { alarmItems.items[i].emit("redraw"); },
|
|
|
|
hide: function () {},
|
|
|
|
run: function() { }
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
return alarmItems;
|
|
|
|
})
|