2022-09-23 14:08:16 +00:00
|
|
|
(function() {
|
|
|
|
const TIMER_IDX = "smpltmr";
|
2023-05-15 08:50:18 +00:00
|
|
|
var alarm = require('sched');
|
2022-09-23 14:08:16 +00:00
|
|
|
|
|
|
|
function isAlarmEnabled(){
|
|
|
|
try{
|
2023-05-15 08:50:18 +00:00
|
|
|
|
2022-09-23 14:08:16 +00:00
|
|
|
var alarmObj = alarm.getAlarm(TIMER_IDX);
|
|
|
|
if(alarmObj===undefined || !alarmObj.on){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch(ex){ }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAlarmMinutes(){
|
|
|
|
if(!isAlarmEnabled()){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
var alarmObj = alarm.getAlarm(TIMER_IDX);
|
|
|
|
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAlarmMinutesText(){
|
|
|
|
var min = getAlarmMinutes();
|
2023-05-15 08:50:18 +00:00
|
|
|
if(min < 0)
|
2022-09-23 14:08:16 +00:00
|
|
|
return "OFF";
|
2024-08-02 14:48:02 +00:00
|
|
|
return min + " min";
|
2022-09-23 14:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function increaseAlarm(t){
|
|
|
|
try{
|
|
|
|
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
|
|
|
|
alarm.setAlarm(TIMER_IDX, {
|
|
|
|
timer : (minutes+t)*60*1000,
|
|
|
|
});
|
|
|
|
alarm.reload();
|
|
|
|
} catch(ex){ }
|
|
|
|
}
|
|
|
|
|
|
|
|
function decreaseAlarm(t){
|
|
|
|
try{
|
|
|
|
var minutes = getAlarmMinutes();
|
|
|
|
minutes -= t;
|
|
|
|
|
|
|
|
alarm.setAlarm(TIMER_IDX, undefined);
|
|
|
|
if(minutes > 0){
|
|
|
|
alarm.setAlarm(TIMER_IDX, {
|
|
|
|
timer : minutes*60*1000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
alarm.reload();
|
|
|
|
} catch(ex){ }
|
|
|
|
}
|
|
|
|
|
|
|
|
var smpltmrItems = {
|
|
|
|
name: "Timer",
|
2022-12-04 15:42:24 +00:00
|
|
|
img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwMMBgPGBgPmDAPjDAPzDAPzDP/zDP/zDH/jBn/mBj/GAw8MA4AcAeB4AH/gAB+AA=="),
|
2022-09-23 14:08:16 +00:00
|
|
|
items: [
|
|
|
|
{
|
2022-10-02 12:30:13 +00:00
|
|
|
name: null,
|
2023-05-15 08:50:18 +00:00
|
|
|
get: () => ({ text: getAlarmMinutesText(), img: smpltmrItems.img } ),
|
|
|
|
show: function() { this.interval = setInterval(()=>this.emit('redraw'), 60000); },
|
|
|
|
hide: function () { clearInterval(this.interval); delete this.interval; },
|
|
|
|
//run: function() { } // should tapping do something?
|
2022-09-23 14:08:16 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2024-03-03 23:04:36 +00:00
|
|
|
const restoreMainItem = function(clkinfo) {
|
|
|
|
clkinfo.menuB = 0;
|
|
|
|
// clock info redraws after this
|
|
|
|
};
|
|
|
|
|
2022-10-02 12:30:13 +00:00
|
|
|
var offsets = [+5,-5];
|
2022-09-23 14:08:16 +00:00
|
|
|
offsets.forEach((o, i) => {
|
|
|
|
smpltmrItems.items = smpltmrItems.items.concat({
|
2022-10-02 12:30:13 +00:00
|
|
|
name: null,
|
2024-08-02 14:48:02 +00:00
|
|
|
get: () => ({ text: (o > 0 ? "+" : "") + o + " min", img: (o>0)?atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgYGBgYGDAYDDAYDDH/jDH/jDAYDDAYDBgYGBgYGAwAMA4AcAeB4AH/gAB+AA=="):atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgAGBgAGDAADDAADDH/jDH/jDAADDAADBgAGBgAGAwAMA4AcAeB4AH/gAB+AA==") }),
|
2023-05-15 08:50:18 +00:00
|
|
|
show: function() { },
|
2024-03-03 23:04:36 +00:00
|
|
|
hide: function() { },
|
|
|
|
blur: restoreMainItem,
|
2022-09-23 14:08:16 +00:00
|
|
|
run: function() {
|
|
|
|
if(o > 0) increaseAlarm(o);
|
|
|
|
else decreaseAlarm(Math.abs(o));
|
|
|
|
this.show();
|
2022-10-02 12:30:13 +00:00
|
|
|
return true;
|
2022-09-23 14:08:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return smpltmrItems;
|
2022-12-14 15:00:29 +00:00
|
|
|
})
|