Add Random Clock Loader widget

pull/415/head
msdeibel 2020-05-12 23:10:14 +02:00
parent d03fb00f2d
commit 069d663253
5 changed files with 48 additions and 0 deletions

View File

@ -1720,5 +1720,17 @@
"data": [ "data": [
{"name":"gallifr.json"} {"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"}
]
} }
] ]

1
apps/rndmclk/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New widget

6
apps/rndmclk/README.md Normal file
View File

@ -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.

BIN
apps/rndmclk/rndmclk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

29
apps/rndmclk/widget.js Normal file
View File

@ -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();
}
});
})();