forked from FOSS/BangleApps
Provide an easy way to run code at boot time #163
parent
dd0e3c89d1
commit
e2247b211d
|
@ -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.info` is JSON that describes an app - this is auto-generated by the App Loader
|
||||||
* `stuff.img` is an image
|
* `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.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
|
* `stuff.json` is used for JSON settings for an app
|
||||||
|
|
||||||
## Developing your own app
|
## Developing your own app
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{ "id": "boot",
|
{ "id": "boot",
|
||||||
"name": "Bootloader",
|
"name": "Bootloader",
|
||||||
"icon": "bootloader.png",
|
"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",
|
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
|
||||||
"tags": "tool,system",
|
"tags": "tool,system",
|
||||||
"type":"bootloader",
|
"type":"bootloader",
|
||||||
|
@ -106,11 +106,12 @@
|
||||||
"name": "Default Alarm",
|
"name": "Default Alarm",
|
||||||
"shortName":"Alarms",
|
"shortName":"Alarms",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"version":"0.04",
|
"version":"0.05",
|
||||||
"description": "Set and respond to alarms",
|
"description": "Set and respond to alarms",
|
||||||
"tags": "tool,alarm,widget",
|
"tags": "tool,alarm,widget",
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"alarm.app.js","url":"app.js"},
|
{"name":"alarm.app.js","url":"app.js"},
|
||||||
|
{"name":"alarm.boot.js","url":"boot.js"},
|
||||||
{"name":"alarm.js","url":"alarm.js"},
|
{"name":"alarm.js","url":"alarm.js"},
|
||||||
{"name":"alarm.json","content":"[]"},
|
{"name":"alarm.json","content":"[]"},
|
||||||
{"name":"alarm.img","url":"app-icon.js","evaluate":true},
|
{"name":"alarm.img","url":"app-icon.js","evaluate":true},
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
0.02: Fix issues with alarm scheduling
|
0.02: Fix issues with alarm scheduling
|
||||||
0.03: More alarm scheduling issues
|
0.03: More alarm scheduling issues
|
||||||
0.04: Tweaks for variable size widget system
|
0.04: Tweaks for variable size widget system
|
||||||
|
0.05: Add alarm.boot.js and move code from the bootloader
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
|
@ -10,3 +10,5 @@
|
||||||
If Debug info is set to 'show' don't move to Terminal if connected!
|
If Debug info is set to 'show' don't move to Terminal if connected!
|
||||||
0.11: Added vibrate as beep workaround
|
0.11: Added vibrate as beep workaround
|
||||||
0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147)
|
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
|
||||||
|
|
|
@ -39,25 +39,7 @@ E.setTimeZone(s.timezone);
|
||||||
delete s;
|
delete s;
|
||||||
// stop users doing bad things!
|
// stop users doing bad things!
|
||||||
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
|
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
|
||||||
// check for alarms
|
// Load *.boot.js files
|
||||||
var alarms = require('Storage').readJSON('alarm.json',1)||[];
|
var clockApps = require('Storage').list(/\.boot\.js/).map(bootFile=>{
|
||||||
var time = new Date();
|
eval(require('Storage').read(bootFile));
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue