Timer ClockInfo now updates once a minute

pull/2758/head
Gordon Williams 2023-05-15 09:50:18 +01:00
parent b5167d7068
commit 1b9df10b08
3 changed files with 12 additions and 17 deletions

View File

@ -5,3 +5,4 @@
0.05: Updated clkinfo icon.
0.06: Ensure Timer supplies an image for clkinfo items
0.07: Update clock_info to avoid a redraw
0.08: Timer ClockInfo now updates once a minute

View File

@ -1,9 +1,10 @@
(function() {
const TIMER_IDX = "smpltmr";
var alarm = require('sched');
function isAlarmEnabled(){
try{
var alarm = require('sched');
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
@ -19,25 +20,20 @@
if(!isAlarmEnabled()){
return -1;
}
var alarm = require('sched');
var alarmObj = alarm.getAlarm(TIMER_IDX);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function getAlarmMinutesText(){
var min = getAlarmMinutes();
if(min < 0){
if(min < 0)
return "OFF";
}
return "T-" + String(min);
return "T-" + String(min)+ " min";
}
function increaseAlarm(t){
try{
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, {
timer : (minutes+t)*60*1000,
});
@ -50,9 +46,7 @@
var minutes = getAlarmMinutes();
minutes -= t;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
timer : minutes*60*1000,
@ -69,10 +63,10 @@
items: [
{
name: null,
get: () => ({ text: getAlarmMinutesText() + (isAlarmEnabled() ? " min" : ""), img: smpltmrItems.img }),
show: function() {},
hide: function () {},
run: function() { }
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?
},
]
};
@ -82,8 +76,8 @@
smpltmrItems.items = smpltmrItems.items.concat({
name: null,
get: () => ({ text: (o > 0 ? "+" : "") + o + " min.", img: smpltmrItems.img }),
show: function() {},
hide: function () {},
show: function() { },
hide: function () { },
run: function() {
if(o > 0) increaseAlarm(o);
else decreaseAlarm(Math.abs(o));

View File

@ -2,7 +2,7 @@
"id": "smpltmr",
"name": "Simple Timer",
"shortName": "Simple Timer",
"version": "0.07",
"version": "0.08",
"description": "A very simple app to start a timer.",
"icon": "app.png",
"tags": "tool,alarm,timer,clkinfo",