fix widchime: make it actually chime the hour instead of crashing

Actually only needs two semicolons to fix, but just add them everywhere
master
Richard de Boer 2021-03-24 11:53:24 +01:00
parent bcc1f8cff2
commit 3fbf14cb23
3 changed files with 15 additions and 14 deletions

View File

@ -585,7 +585,7 @@
{ "id": "widchime",
"name": "Hour Chime",
"icon": "widget.png",
"version":"0.01",
"version":"0.02",
"description": "Buzz or beep on every whole hour.",
"tags": "widget",
"type": "widget",

View File

@ -1 +1,2 @@
0.01: First version
0.02: Bugfix: now it actually chimes the hour instead of crashing

View File

@ -1,26 +1,26 @@
(function() {
// 0: off, 1: buzz, 2: beep, 3: both
const type = (require("Storage").readJSON("widchime.json", 1) || {type: 1}).type
if (!type) return
const type = (require("Storage").readJSON("widchime.json", 1) || {type: 1}).type;
if (!type) return;
function chime() {
if ((require("Storage").readJSON("setting.json", 1) || {}).quiet) return
if (type&1) Bangle.buzz(100)
if (type&2) Bangle.beep()
if ((require("Storage").readJSON("setting.json", 1) || {}).quiet) return;
if (type&1) Bangle.buzz(100);
if (type&2) Bangle.beep();
}
let lastHour = (new Date()).getHours() // don't chime when (re)loaded at a whole hour
let lastHour = (new Date()).getHours(); // don't chime when (re)loaded at a whole hour
function check() {
const now = new Date(),
h = now.getHours(), m = now.getMinutes(),
s = now.getSeconds(), ms = now.getMilliseconds()
if (h!==lastHour && m===0) chime()
lastHour = h
s = now.getSeconds(), ms = now.getMilliseconds();
if (h!==lastHour && m===0) chime();
lastHour = h;
// check again when this hour is over
const mLeft = 60-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms
setTimeout(check, msLeft)
const mLeft = 60-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms;
setTimeout(check, msLeft);
}
check()
check();
})
()
();