2021-03-25 22:25:04 +00:00
|
|
|
// apply Quiet Mode schedules
|
|
|
|
(function qm() {
|
2022-01-12 18:08:19 +00:00
|
|
|
if (Bangle.qmTimeout) clearTimeout(Bangle.qmTimeout); // so the app can eval() this file to apply changes right away
|
|
|
|
delete Bangle.qmTimeout;
|
2021-11-26 19:05:40 +00:00
|
|
|
let bSettings = require('Storage').readJSON('setting.json',true)||{};
|
|
|
|
const curr = 0|bSettings.quiet;
|
|
|
|
delete bSettings;
|
|
|
|
if (curr) require("qmsched").applyOptions(curr); // no need to re-apply default options
|
|
|
|
|
|
|
|
let settings = require('Storage').readJSON('qmsched.json',true)||{};
|
|
|
|
let scheds = settings.scheds||[];
|
|
|
|
if (!scheds.length) {return;}
|
2021-03-25 22:25:04 +00:00
|
|
|
const now = new Date(),
|
2021-08-10 20:26:17 +00:00
|
|
|
hr = now.getHours()+(now.getMinutes()/60)+(now.getSeconds()/3600); // current (decimal) hour
|
|
|
|
scheds.sort((a, b) => a.hr-b.hr);
|
|
|
|
const tday = scheds.filter(s => s.hr>hr), // scheduled for today
|
|
|
|
tmor = scheds.filter(s => s.hr<=hr); // scheduled for tomorrow
|
|
|
|
const next = tday.length ? tday[0] : tmor[0],
|
|
|
|
mode = next.mode;
|
|
|
|
let t = 3600000*(next.hr-hr); // timeout in milliseconds
|
|
|
|
if (t<0) {t += 86400000;} // scheduled for tomorrow: add a day
|
2021-03-25 22:25:04 +00:00
|
|
|
/* update quiet mode at the correct time. */
|
2022-01-12 18:08:19 +00:00
|
|
|
Bangle.qmTimeout=setTimeout(() => {
|
2021-08-10 20:26:17 +00:00
|
|
|
require("qmsched").setMode(mode);
|
2021-03-25 22:25:04 +00:00
|
|
|
qm(); // schedule next update
|
|
|
|
}, t);
|
|
|
|
})();
|