diff --git a/README.md b/README.md index 0fcb78608..2d0b54a7d 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,9 @@ easily distinguish between file types, we use the following: * `stuff.info` is JSON that describes an app - this is auto-generated by the App Loader * `stuff.img` is an image -* `stuff.app.js` is JS code +* `stuff.app.js` is JS code for applications * `stuff.wid.js` is JS code for widgets +* `stuff.boot.js` is JS code that automatically gets run at boot time * `stuff.json` is used for JSON settings for an app ## Developing your own app diff --git a/apps.json b/apps.json index 5c88edb9c..26951eb55 100644 --- a/apps.json +++ b/apps.json @@ -2,7 +2,7 @@ { "id": "boot", "name": "Bootloader", "icon": "bootloader.png", - "version":"0.12", + "version":"0.13", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "tags": "tool,system", "type":"bootloader", @@ -106,11 +106,12 @@ "name": "Default Alarm", "shortName":"Alarms", "icon": "app.png", - "version":"0.04", + "version":"0.05", "description": "Set and respond to alarms", "tags": "tool,alarm,widget", "storage": [ {"name":"alarm.app.js","url":"app.js"}, + {"name":"alarm.boot.js","url":"boot.js"}, {"name":"alarm.js","url":"alarm.js"}, {"name":"alarm.json","content":"[]"}, {"name":"alarm.img","url":"app-icon.js","evaluate":true}, diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index 67feb024f..be3c1513c 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -2,3 +2,4 @@ 0.02: Fix issues with alarm scheduling 0.03: More alarm scheduling issues 0.04: Tweaks for variable size widget system +0.05: Add alarm.boot.js and move code from the bootloader diff --git a/apps/alarm/boot.js b/apps/alarm/boot.js new file mode 100644 index 000000000..709703bdd --- /dev/null +++ b/apps/alarm/boot.js @@ -0,0 +1,24 @@ +// check for alarms +(function() { + var alarms = require('Storage').readJSON('alarm.json',1)||[]; + var time = new Date(); + var active = alarms.filter(a=>a.on&&(a.last!=time.getDate())); + if (active.length) { + active = active.sort((a,b)=>a.hr-b.hr); + 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',"[]") + } else { + var t = 3600000*(active[0].hr-hr); + 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 + will then clearInterval() to get rid of this call so it can proceed + normally. */ + setTimeout(function() { + load("alarm.js"); + },t); + } + } +})() diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 93f03b8ad..17023a8dc 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -10,3 +10,5 @@ If Debug info is set to 'show' don't move to Terminal if connected! 0.11: Added vibrate as beep workaround 0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147) +0.13: Now automatically load *.boot.js at startup + Move alarm code into alarm.boot.js diff --git a/apps/boot/boot0.js b/apps/boot/boot0.js index ad8ccb312..729b7aaf2 100644 --- a/apps/boot/boot0.js +++ b/apps/boot/boot0.js @@ -39,25 +39,7 @@ E.setTimeZone(s.timezone); delete s; // stop users doing bad things! global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); } -// check for alarms -var alarms = require('Storage').readJSON('alarm.json',1)||[]; -var time = new Date(); -var active = alarms.filter(a=>a.on&&(a.last!=time.getDate())); -if (active.length) { - active = active.sort((a,b)=>a.hr-b.hr); - 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',"[]") - } else { - var t = 3600000*(active[0].hr-hr); - 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 - will then clearInterval() to get rid of this call so it can proceed - normally. */ - setTimeout(function() { - load("alarm.js"); - },t); - } -} +// Load *.boot.js files +var clockApps = require('Storage').list(/\.boot\.js/).map(bootFile=>{ + eval(require('Storage').read(bootFile)); +});