From b13c5d13f405747ed3578ac64a2291e9a6173af0 Mon Sep 17 00:00:00 2001 From: Sabin Iacob Date: Wed, 27 May 2020 08:14:48 +0300 Subject: [PATCH 1/3] Make the alarm scheduling more reliable Fixes https://github.com/espruino/BangleApps/issues/433 --- apps/alarm/boot.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/alarm/boot.js b/apps/alarm/boot.js index 709703bdd..a0c8fa6ed 100644 --- a/apps/alarm/boot.js +++ b/apps/alarm/boot.js @@ -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 += 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); } } -})() +})(); From 8e8e56098ada271782936c23c33730550ad52203 Mon Sep 17 00:00:00 2001 From: Sabin Iacob Date: Wed, 27 May 2020 11:47:20 +0300 Subject: [PATCH 2/3] Bump alarm version --- apps.json | 2 +- apps/alarm/ChangeLog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps.json b/apps.json index f0ceaeb35..8feb713e9 100644 --- a/apps.json +++ b/apps.json @@ -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": [ diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index ca92a0d97..b05d64676 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -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 From cb491d06780e9a37dc6748902e79ae4d112ee904 Mon Sep 17 00:00:00 2001 From: Sabin Iacob Date: Wed, 27 May 2020 11:55:15 +0300 Subject: [PATCH 3/3] also schedule the alarm for the next day if the alarm time is less than current time --- apps/alarm/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/alarm/boot.js b/apps/alarm/boot.js index a0c8fa6ed..47dae5361 100644 --- a/apps/alarm/boot.js +++ b/apps/alarm/boot.js @@ -11,7 +11,7 @@ require('Storage').write('alarm.json',"[]"); } else { var t = 3600000*(active[0].hr-hr); - if (active[0].last == time.getDate()) t += 86400000; + 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