Added first version of Chimer app

master
Aaron Rolls 2022-08-23 08:49:10 +12:00
parent fb7b69379a
commit ec7e58a14d
5 changed files with 120 additions and 0 deletions

2
apps/chimer/icon.txt Normal file
View File

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

15
apps/chimer/metadata.json Normal file
View File

@ -0,0 +1,15 @@
{
"id": "chimer",
"name": "Chimer",
"version": "0.01",
"description": "A fork of Hour Chime. Buzz or beep on every 60, 30 or 15 minutes.",
"icon": "widget.png",
"type": "widget",
"tags": "widget",
"supports": ["BANGLEJS","BANGLEJS2"],
"storage": [
{"name":"widchime.wid.js","url":"widget.js"},
{"name":"widchime.settings.js","url":"settings.js"}
],
"data": [{"name":"widchime.json"}]
}

54
apps/chimer/settings.js Normal file
View File

@ -0,0 +1,54 @@
/**
* @param {function} back Use back() to return to settings menu
*/
(function(back) {
// default to buzzing
var FILE = "chimer.json"
var settings = {}
const chimes = ["Off", "Buzz", "Beep", "Both"]
const frequency = ["60 min", "30 min", "15 min"]
const menu = {
"": {"title": "Hour Chime"},
"< Back": back,
"Chime Type": {
value: settings.type,
min: 0, max: 2, // both is just silly
format: v => chimes[v],
onchange: function(v) {
settings.type = v
writeSettings(settings)
},
},
"Frequency": {
value: settings.freq,
min: 0, max: 2,
format: v => frequency[v],
onchange : function(v) {
settings.freq = v
writeSettings(settings)
}
}
}
var readSettings = () => {
var settings = require("Storage").readJSON(FILE, 1) || {
type: 1,
freq: 0,
};
return settings;
};
var writeSettings = (settings) => {
require("Storage").writeJSON(FILE, settings);
};
settings = readSettings()
E.showMenu(menu)
})

49
apps/chimer/widget.js Normal file
View File

@ -0,0 +1,49 @@
(function() {
// 0: off, 1: buzz, 2: beep, 3: both
var readSettings = () => {
var settings = require("Storage").readJSON(FILE, 1) || {
type: 1,
freq: 0,
};
return settings;
};
var settings = readSettings()
function chime() {
if (settings.type == 0) return;
if (settings.type&1) Bangle.buzz(100);
if (settings.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 (settings.freq == 1){
if (h!==lastHour && m===30) chime();
lastHour = h;
// check again in 30 minutes
const mLeft = 30-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms;
setTimeout(check, msLeft);
}else if (settings.freq == 2){
if (h!==lastHour && m===15) chime();
lastHour = h;
// check again in 15 minutes
const mLeft = 15-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms;
setTimeout(check, msLeft);
}else{
if (h!==lastHour && m===0) chime();
lastHour = h;
// check again in 60 minutes
const mLeft = 60-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms;
setTimeout(check, msLeft);
}
}
check();
})
();

BIN
apps/chimer/widget.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB