forked from FOSS/BangleApps
Fix #1583.
Fix timers doubling (plus a bit) when they expire. Timer reset restores to configured time, not to the default. Added surise/sunset times (hidden by default).master
parent
2b32bc37e2
commit
178b011c34
|
@ -1 +1,2 @@
|
|||
0.01: New App!
|
||||
0.02: Add sunrise/sunset. Fix timer bugs.
|
||||
|
|
|
@ -11,6 +11,7 @@ A clock based on the Anton Clock with stopwatches, timers and alarms based on th
|
|||
* alarms
|
||||
* multiple stopwatches, timers and alarms
|
||||
* stopwatches and timers keep running in the background
|
||||
* optional time of sunrise/sunset using the My Location app - hidden by default
|
||||
|
||||
## Images
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"id":"timerclk","name":"tclk Alarm","src":"timerclk.alarm.js","icon":"timerclk.img","version":"0.01","tags":"","files":"","sortorder":10}
|
File diff suppressed because one or more lines are too long
|
@ -1,26 +1,17 @@
|
|||
var timerclkTimerTimeout;
|
||||
var timerclkAlarmTimeout;
|
||||
function timerclkCheckTimers() {
|
||||
var expiresIn=require("timerclk.lib.js").timerExpiresIn;
|
||||
if (timerclkTimerTimeout) clearTimeout(timerclkTimerTimeout);
|
||||
var timers = require('Storage').readJSON('timerclk.timer.json',1)||[];
|
||||
timers = timers.filter(e=>e.start);
|
||||
if (timers.length) {
|
||||
timers = timers.sort((a,b)=>{
|
||||
var at = a.timeAdd;
|
||||
if (a.start) at += Date.now()-a.start;
|
||||
at = a.period-at;
|
||||
var bt = b.timeAdd;
|
||||
if (b.start) bt += Date.now()-b.start;
|
||||
bt = b.period-bt;
|
||||
return at-bt;
|
||||
});
|
||||
timers = timers.sort((a,b)=>expiresIn(a)-expiresIn(b));
|
||||
if (!require('Storage').read("timerclk.timer.alert.js")) {
|
||||
console.log("No timer app!");
|
||||
} else {
|
||||
var time = timers[0].timeAdd;
|
||||
if (timers[0].start) time += Date.now()-timers[0].start;
|
||||
time = timers[0].time - time;
|
||||
if (time<1000) t=1000;
|
||||
var time = expiresIn(timers[0]);
|
||||
if (time<1000) time=1000;
|
||||
if (timerclkTimerTimeout) clearTimeout(timerclkTimerTimeout);
|
||||
timerclkTimerTimeout = setTimeout(() => load("timerclk.timer.alert.js"),time);
|
||||
}
|
||||
|
@ -38,7 +29,7 @@ function timerclkCheckAlarms() {
|
|||
} else {
|
||||
var time = alarms[0].time-currentTime;
|
||||
if (alarms[0].last == new Date().getDate() || time < 0) time += 86400000;
|
||||
if (time<1000) t=1000;
|
||||
if (time<1000) time=1000;
|
||||
if (timerclkAlarmTimeout) clearTimeout(timerclkAlarmTimeout);
|
||||
timerclkAlarmTimeout = setTimeout(() => load("timerclk.alarm.alert.js"),time);
|
||||
}
|
||||
|
|
|
@ -125,3 +125,5 @@ exports.registerControls = function(o) {
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.timerExpiresIn=t=>t.time-(Date.now()-t.start);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id": "timerclk",
|
||||
"name": "Timer Clock",
|
||||
"shortName":"Timer Clock",
|
||||
"version":"0.01",
|
||||
"version":"0.02",
|
||||
"description": "A clock with stopwatches, timers and alarms build in.",
|
||||
"icon": "app-icon.png",
|
||||
"type": "clock",
|
||||
|
@ -29,9 +29,6 @@
|
|||
{"name":"timerclk.timer.alert.js","url":"timer.alert.js"},
|
||||
{"name":"timerclk.alarm.js","url":"alarm.js"},
|
||||
{"name":"timerclk.alarm.alert.js","url":"alarm.alert.js"},
|
||||
{"name":"timerclk.stopwatch.info","url":"stopwatch.info"},
|
||||
{"name":"timerclk.timer.info","url":"timer.info"},
|
||||
{"name":"timerclk.alarm.info","url":"alarm.info"}
|
||||
],
|
||||
"data": [{"name":"timerclk.json"},{"name":"timerclk.stopwatch.json"},{"name":"timerclk.timer.json"},{"name":"timerclk.alarm.json"}],
|
||||
"sortorder": 0
|
||||
|
|
|
@ -12,9 +12,12 @@
|
|||
"dowFontSize":2,
|
||||
"specialFont":"6x8",
|
||||
"specialFontSize":2,
|
||||
"srssFont":"6x8",
|
||||
"srssFontSize":2,
|
||||
"shortDate":true,
|
||||
"showStopwatches":true,
|
||||
"showTimers":true,
|
||||
"showSrss":false,
|
||||
}, settings.clock||{});
|
||||
settings.stopwatch = Object.assign({
|
||||
"font":"Vector",
|
||||
|
@ -108,6 +111,23 @@
|
|||
writeSettings();
|
||||
}
|
||||
},
|
||||
"sun font":{
|
||||
value: 0|g.getFonts().indexOf(settings.clock.srssFont),
|
||||
format: v => g.getFonts()[v],
|
||||
min: 0, max: g.getFonts().length-1,
|
||||
onchange: v => {
|
||||
settings.clock.srssFont = g.getFonts()[v];
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
"sun size":{
|
||||
value: 0|settings.clock.srssFontSize,
|
||||
min: 0,
|
||||
onchange: v => {
|
||||
settings.clock.srssFontSize = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
"short date": {
|
||||
value: !!settings.clock.shortDate,
|
||||
format: BOOL_FORMAT,
|
||||
|
@ -132,6 +152,14 @@
|
|||
writeSettings();
|
||||
}
|
||||
},
|
||||
"sun times": {
|
||||
value: !!settings.clock.showSrss,
|
||||
format: v=>v?/*LANG*/"Show":/*LANG*/"Hide",
|
||||
onchange: v => {
|
||||
settings.clock.showSrss = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var stopwatchMenu = {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"id":"timerclk","name":"tclk Stopwatch","src":"timerclk.stopwatch.js","icon":"timerclk.img","version":"0.01","tags":"","files":"","sortorder":10}
|
|
@ -14,10 +14,7 @@ function showTimer(timer) {
|
|||
buttons : {/*LANG*/"Ok":true}
|
||||
}).then(function(ok) {
|
||||
buzzCount = 0;
|
||||
if (ok) {
|
||||
timer.time += Date.now() - timer.start;
|
||||
timer.start = null;
|
||||
}
|
||||
timer.start = null;
|
||||
require("Storage").write("timerclk.timer.json",JSON.stringify(timers));
|
||||
load();
|
||||
});
|
||||
|
@ -45,16 +42,8 @@ console.log("checking for timers...");
|
|||
var timers = require("Storage").readJSON("timerclk.timer.json",1)||[];
|
||||
var active = timers.filter(e=>e.start);
|
||||
if (active.length) {
|
||||
// if there's an timer, show it
|
||||
active = active.sort((a,b)=>{
|
||||
var at = a.time;
|
||||
if (a.start) at += Date.now()-a.start;
|
||||
at = a.period-at;
|
||||
var bt = b.time;
|
||||
if (b.start) bt += Date.now()-b.start;
|
||||
bt = b.period-bt;
|
||||
return at-bt;
|
||||
});
|
||||
// if there's an active timer, show it
|
||||
active = active.sort((a,b)=>timerclk.timerExpiresIn(a)-timerclk.timerExpiresIn(b));
|
||||
showTimer(active[0]);
|
||||
} else {
|
||||
// otherwise just go back to default app
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"id":"timerclk","name":"tclk Timer","src":"timerclk.timer.js","icon":"timerclk.img","version":"0.01","tags":"","files":"","sortorder":10}
|
|
@ -34,18 +34,20 @@ function update() {
|
|||
}
|
||||
function play() {
|
||||
if (all[current].start) { // running
|
||||
all[current].timeAdd += Date.now() - all[current].start;
|
||||
all[current].timeAdd = Date.now() - all[current].start;
|
||||
all[current].start = null;
|
||||
update();
|
||||
} else { // paused
|
||||
all[current].start = Date.now();
|
||||
all[current].start = Date.now() - all[current].timeAdd;
|
||||
all[current].timeAdd = 0;
|
||||
update();
|
||||
}
|
||||
require("Storage").write("timerclk.timer.json",JSON.stringify(all));
|
||||
timerclkCheckTimers();
|
||||
}
|
||||
function reset() {
|
||||
all[current] = defaultElement.clone();
|
||||
all[current].start = null;
|
||||
all[current].timeAdd = 0;
|
||||
update();
|
||||
require("Storage").write("timerclk.timer.json",JSON.stringify(all));
|
||||
timerclkCheckTimers();
|
||||
|
|
Loading…
Reference in New Issue