mirror of https://github.com/espruino/BangleApps
widchime: simple hour chime
parent
e969ebf140
commit
6345aa604c
15
apps.json
15
apps.json
|
@ -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",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0.01: First version
|
|
@ -0,0 +1 @@
|
|||
widget.png: https://icons8.com/icon/15715/plus-1-hour
|
|
@ -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)
|
||||
})
|
|
@ -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()
|
||||
})
|
||||
()
|
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in New Issue