BangleApps/apps/keytimer/common.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-12 22:40:51 +00:00
const sched = require('sched');
const storage = require('Storage');
2023-05-12 22:40:51 +00:00
exports.running = function () {
return sched.getAlarm('keytimer') != undefined;
};
2023-05-12 22:40:51 +00:00
exports.timerExists = function () {
return exports.running() || (exports.state.timeLeft != 0);
}
//Get the number of milliseconds until the timer expires
exports.getTimeLeft = function () {
2023-05-12 22:40:51 +00:00
if (exports.running()) {
return sched.getTimeToAlarm(sched.getAlarm('keytimer'));
} else {
2023-05-12 22:40:51 +00:00
return exports.state.timeLeft;
}
2023-05-12 22:40:51 +00:00
}
exports.state = storage.readJSON('keytimer.json') || {
inputString: '0',
timeLeft: 0
};
exports.startTimer = function (time) {
let timer = sched.newDefaultTimer();
timer.timer = time;
common.state.timeLeft = time;
timer.del = true;
timer.appid = 'keytimer';
timer.js = "load('keytimer-ring.js')";
sched.setAlarm('keytimer', timer);
sched.reload();
}
exports.pauseTimer = function () {
exports.state.timeLeft = exports.getTimeLeft();
sched.setAlarm('keytimer');
sched.reload();
}
2023-05-12 22:40:51 +00:00
exports.deleteTimer = function () {
sched.setAlarm('keytimer');
exports.state.timeLeft = 0;
sched.reload();
}