1
0
Fork 0

Merge pull request #455 from m0n5t3r/master

Make the alarm scheduling more reliable
master
Gordon Williams 2020-05-27 10:55:39 +01:00 committed by GitHub
commit d0f5aed573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -137,7 +137,7 @@
"name": "Default Alarm",
"shortName":"Alarms",
"icon": "app.png",
"version":"0.07",
"version":"0.08",
"description": "Set and respond to alarms",
"tags": "tool,alarm,widget",
"storage": [

View File

@ -5,3 +5,4 @@
0.05: Add alarm.boot.js and move code from the bootloader
0.06: Change 'New Alarm' to 'Save', allow Deletion of Alarms
0.07: Don't overwrite existing settings on app update
0.08: Make alarm scheduling more reliable

View File

@ -2,15 +2,16 @@
(function() {
var alarms = require('Storage').readJSON('alarm.json',1)||[];
var time = new Date();
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate()));
var active = alarms.filter(a=>a.on);
if (active.length) {
active = active.sort((a,b)=>a.hr-b.hr);
active = active.sort((a,b)=>(a.hr-b.hr)+(a.last-b.last)*24);
var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600);
if (!require('Storage').read("alarm.js")) {
console.log("No alarm app!");
require('Storage').write('alarm.json',"[]")
require('Storage').write('alarm.json',"[]");
} else {
var t = 3600000*(active[0].hr-hr);
if (active[0].last == time.getDate() || t < 0) t += 86400000;
if (t<1000) t=1000;
/* execute alarm at the correct time. We avoid execing immediately
since this code will get called AGAIN when alarm.js is loaded. alarm.js
@ -21,4 +22,4 @@
},t);
}
}
})()
})();