widchime: simple hour chime

pull/698/head
Richard de Boer 2021-03-20 20:53:53 +01:00
parent e969ebf140
commit 6345aa604c
6 changed files with 65 additions and 0 deletions

View File

@ -569,6 +569,21 @@
{"name":"widbt.wid.js","url":"widget.js"}
]
},
{ "id": "widchime",
"name": "Hour Chime",
"icon": "widget.png",
"version":"0.01",
"description": "Buzz or beep on every whole hour.",
"tags": "widget",
"type": "widget",
"storage": [
{"name":"widchime.wid.js","url":"widget.js"},
{"name":"widchime.settings.js","url":"settings.js"}
],
"data": [
{"name":"widchime.json"}
]
},
{ "id": "widram",
"name": "RAM Widget",
"shortName":"RAM Widget",

1
apps/widchime/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: First version

1
apps/widchime/icons.txt Normal file
View File

@ -0,0 +1 @@
widget.png: https://icons8.com/icon/15715/plus-1-hour

22
apps/widchime/settings.js Normal file
View File

@ -0,0 +1,22 @@
/**
* @param {function} back Use back() to return to settings menu
*/
(function(back) {
// default to buzzing
let type = (require("Storage").readJSON("widchime.json", 1) || {type: 1}).type|0
const chimes = ["Off", "Buzz", "Beep", "Both"]
const menu = {
"": {"title": "Hour Chime"},
"< Back": back,
"Chime Type": {
value: type,
min: 0, max: 2, // both is just silly
format: v => chimes[v],
onchange: function(v) {
type = v
require("Storage").write("widchime.json", {type: v})
},
},
}
E.showMenu(menu)
})

26
apps/widchime/widget.js Normal file
View File

@ -0,0 +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
function chime() {
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
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
// check again when this hour is over
const mLeft = 60-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms
setTimeout(check, msLeft)
}
check()
})
()

BIN
apps/widchime/widget.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB