forked from FOSS/BangleApps
Add Random Clock Loader widget
parent
d03fb00f2d
commit
069d663253
12
apps.json
12
apps.json
|
@ -1720,5 +1720,17 @@
|
|||
"data": [
|
||||
{"name":"gallifr.json"}
|
||||
]
|
||||
},
|
||||
{ "id": "rndmclk",
|
||||
"name": "Random Clock Loader",
|
||||
"icon": "rndmclk.png",
|
||||
"version":"0.01",
|
||||
"description": "Load a different clock whenever the LCD is switched on.",
|
||||
"readme": "README.md",
|
||||
"tags": "widget,clock",
|
||||
"type":"widget",
|
||||
"storage": [
|
||||
{"name":"rndmclk.wid.js","url":"widget.js"}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0.01: New widget
|
|
@ -0,0 +1,6 @@
|
|||
# Summary
|
||||
|
||||
Random Clock is a widget that will randomly show one of the installed watch faces each time the LCD is turned on.
|
||||
|
||||
## Disclaimer
|
||||
This is an early version and will load a clock each time the LCD is turned on no matter what app was running before the screen went to standby. Also the next watch face is only loaded after the last one is shown for a few tens of seconds.
|
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -0,0 +1,29 @@
|
|||
(() => {
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
Loading…
Reference in New Issue