1
0
Fork 0
BangleApps/apps/rndmclk/widget.js

29 lines
788 B
JavaScript
Raw Normal View History

2020-05-12 21:10:14 +00:00
(() => {
/**
* Random value between zero (inclusive) and max (exclusive)
* @param {int} max
*/
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function loadRandomClock() {
// Find available clock apps (same way as in the bootloader)
var clockApps = require("Storage").list(/\.info$/).map(app => require("Storage").readJSON(app, 1) || {}).filter(app => app.type == "clock").sort((a, b) => a.sortorder - b.sortorder);
if (clockApps && clockApps.length > 0) {
var clockIndex = getRandomInt(clockApps.length);
load(clockApps[clockIndex].src);
}
}
Bangle.on('lcdPower', (on) => {
if (on) {
// TODO: Only run if the current app is a clock as well
loadRandomClock();
}
});
})();