add hourstrike -- a new app

pull/715/head
Weiming 2021-03-28 22:34:25 -04:00
parent 6c481a118b
commit 9f82c9ce50
7 changed files with 118 additions and 1 deletions

View File

@ -3059,5 +3059,20 @@
{"name":"waypoints.json","url":"waypoints.json","evaluate":false},
{"name":"kitchen.img","url":"kitchen.icon.js","evaluate":true}
]
}
},
{
"id": "hourstrike",
"name": "Hour Strike",
"shortName": "Hour Strike",
"icon": "app.png",
"version": "0.01",
"description": "Strike the clock on the hour. A great tool to remind you an hour has passed!",
"tags": "tool,alarm,widget",
"readme": "README.md",
"storage": [
{"name":"hourstrike.app.js","url":"app.js"},
{"name":"hourstrike.boot.js","url":"boot.js"},
{"name":"hourstrike.img","url":"app-icon.js","evaluate":true}
]
}
]

View File

@ -0,0 +1 @@
0.01: New App!

17
apps/hourstrike/READMS.md Normal file
View File

@ -0,0 +1,17 @@
# Hour Strike
![icon](app-icon.png)
Time passes too fast!
This app configures your `Bangle.js` so that it buzzes on the hour or on the half hour.
## Features
- Strikes the hour or the half hour
- Set up a quiet time
## Creator
[Weiming Hu](https://weiming-hu.github.io/), using coding from the [Default Alarm](https://github.com/espruino/BangleApps/tree/master/apps/alarm).

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwkGswAHogAEBxAAHsgXFowXPCwowQFwwwQCIUjn/zmQwPFwUj/4ACDAQwMBwNDCgPwh4DBmgwMFwU/C4vzGBgMBoRECC4f/kgwLIwgXFJBgLBl4XH+QXNLwQXFMAQXPmEDC6K8DiEBAoYXSgA1DI6MxgETL6gYBgIGBC5ynDCYMQAwKnOa4YABmTXQoQXEAAUkC5dkMAx2EowXJJBBGNAAMUBwMjMAgHBoIXLiIPBDAM/+YWCokRC5gwCAAtBC5owDAAgJBC5dBiAwGoMBigXLokQgIXFA4QXMoEAAANNqAECggXR7oXXAYQXSgvUC6sEC60N6oXW6AXUinu8IXTgPuAAMQC6UEC4SsDC58OC4XgC9RHXO66nCoLXVAAoXmABQX1A"))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

62
apps/hourstrike/app.js Normal file
View File

@ -0,0 +1,62 @@
const storage = require('Storage');
let settings;
function updateSettings() {
storage.write('hourstrike.json', settings);
}
function resetSettings() {
settings = {
on_hour: true,
on_half_hour: true,
start_hour: 9,
end_hour: 21,
};
updateSettings();
}
settings = storage.readJSON('hourstrike.json', 1);
if (!settings) resetSettings();
function showMainMenu() {
var mode = ['off', 'v', 'b', 'vb', 'bv'];
const mainmenu = {
'': { 'title': 'Time Passed' },
'On hour': {
value: settings.on_hour,
format: v => v?"ON":"OFF",
onchange: v => {
settings.on_hour = v;
updateSettings();
}
},
'On half hour': {
value: settings.on_half_hour,
format: v => v?"ON":"OFF",
onchange: v => {
settings.on_half_hour = v;
updateSettings();
}
},
'Start hour': {
value: settings.start_hour,
min: 0, max: 23,
onchange: v=> {
settings.start_hour = v;
updateSettings();
}
},
'End hour': {
value: settings.end_hour,
min: 0, max: 23,
onchange: v=> {
settings.end_hour = v;
updateSettings();
}
},
'< Back': ()=>load()
};
return E.showMenu(mainmenu);
}
showMainMenu();

21
apps/hourstrike/boot.js Normal file
View File

@ -0,0 +1,21 @@
(function() {
var setting = require('Storage').readJSON('hourstrike.json',1)||[];
if (setting.on_hour || setting.on_harlf_hour) {
var cur = new Date();
var cur_hour = cur.getHours();
if (setting.start_hour<=cur_hour&&cur_hour<=setting.end_hour) {
var cur_sec = cur.getMinutes()*60+cur.getSeconds();
var notify_on = [1800, 3600];
var t=cur_sec<notify_on[0]?notify_on[0]-cur_sec:notify_on[1]-cur_sec;
var notify_func = function() {
Bangle.buzz(100, 0.5)
.then(() => new Promise(resolve => setTimeout(resolve,200)))
.then(() => Bangle.buzz(100, 0.5));
};
if (t>0) {
setTimeout(notify_func, t*1000);
setTimeout(load, t*1000 + 600);
}
}
}
})();