|
1 | | -(() => { |
2 | | - const LOOP_INTERVAL = 1.2e6; // 20 minutes |
3 | | - const BUZZ_INTERVAL = 2e4; // 20 seconds |
4 | | - |
5 | | - const isWorkTime = (d) => |
6 | | - d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; |
7 | | - |
8 | | - const scheduleNext = () => { |
9 | | - const now = new Date(); |
10 | | - if (isWorkTime(now)) { |
11 | | - Bangle.buzz().then(() => setTimeout(Bangle.buzz, BUZZ_INTERVAL)); |
12 | | - setTimeout(scheduleNext, LOOP_INTERVAL); |
13 | | - } else { |
14 | | - const next = new Date(now+864e5); // 24 hours |
15 | | - next.setHours(8, 0, 0, 0); |
16 | | - while (!isWorkTime(next)) next.setDate(next.getDate() + 1); |
17 | | - setTimeout(scheduleNext, next - now); |
18 | | - } |
19 | | - }; |
20 | | - |
21 | | - // Align so we fire at whole hour, 20 min past and 40 min past - not at arbitrary times. |
22 | | - const TIME_AT_BOOT = new Date(); |
23 | | - const TIME_SINCE_WHOLE_THIRD_OF_HOUR = (TIME_AT_BOOT.getMinutes() % 20) * 6e4 + TIME_AT_BOOT.getSeconds() * 1e3; |
24 | | - setTimeout(scheduleNext, |
25 | | - LOOP_INTERVAL - TIME_SINCE_WHOLE_THIRD_OF_HOUR); |
26 | | - // Make sure we don't miss the 2nd buzz after 20 seconds if we rebooted during that interval. |
27 | | - if (TIME_SINCE_WHOLE_THIRD_OF_HOUR <= BUZZ_INTERVAL) { |
28 | | - setTimeout(Bangle.buzz, |
29 | | - BUZZ_INTERVAL - TIME_SINCE_WHOLE_THIRD_OF_HOUR); |
30 | | - } |
31 | | -})(); |
| 1 | +{ // This boot script is deleted once the companion alarm is set up. |
| 2 | + // The app will continue working by having the alarm rearm itself until |
| 3 | + // the app is uninstalled. |
| 4 | + require("twenties").setup(); |
| 5 | + setTimeout(require("Storage").erase, 1000, "twenties.boot.js"); |
| 6 | +} |
0 commit comments