Merge pull request #424 from msdeibel/master

Reduce invasiveness of RndmClk
pull/429/head
Gordon Williams 2020-05-15 15:17:07 +01:00 committed by GitHub
commit fcd5a06e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -1725,7 +1725,7 @@
{ "id": "rndmclk",
"name": "Random Clock Loader",
"icon": "rndmclk.png",
"version":"0.01",
"version":"0.02",
"description": "Load a different clock whenever the LCD is switched on.",
"readme": "README.md",
"tags": "widget,clock",

View File

@ -1 +1,2 @@
0.01: New widget
0.02: Less invasive, change default clock setting instead of directly loading the new clock (no longer breaks Gadgetbridge notifications)

View File

@ -1,6 +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.
# How it works
Everytime the LCD is turned off, the widget randomly changes the clock. When you long press BTN 3 the next time,
you might (or might not, it's random after all) see another watch face.

View File

@ -1,4 +1,5 @@
(() => {
let currentClock = "";
/**
* Random value between zero (inclusive) and max (exclusive)
@ -15,13 +16,18 @@
if (clockApps && clockApps.length > 0) {
var clockIndex = getRandomInt(clockApps.length);
load(clockApps[clockIndex].src);
// Only update the file if the clock really change to be nice to the FLASH mem
if (clockApps[clockIndex].src != currentClock) {
currentClock = clockApps[clockIndex].src;
settings = require("Storage").readJSON('setting.json', 1);
settings.clock = clockApps[clockIndex].src;
require("Storage").write('setting.json', settings);
}
}
}
Bangle.on('lcdPower', (on) => {
if (on) {
// TODO: Only run if the current app is a clock as well
if (!on) {
loadRandomClock();
}
});