trying to resolve the issue for quiet time

master
Weiming 2021-03-28 23:28:45 -04:00
parent 794b85834c
commit 4574726f5d
1 changed files with 23 additions and 15 deletions

View File

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