Compare commits

...

4 Commits

Author SHA1 Message Date
14bda5c29f Use clearInterval to clear the stopwatch interval 2026-03-10 16:58:57 -06:00
ea58f2101f Increase buzz duration 2026-03-10 16:54:44 -06:00
07bb582ddd feat: Initialize buzz state for stopwatches
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
2026-03-10 16:22:44 -06:00
6d965dd016 feat: Add timed buzzing alerts to stopwatches
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
2026-03-10 16:22:18 -06:00

View File

@@ -11,7 +11,7 @@
let watchState = STATE_IDLE; let watchState = STATE_IDLE;
let stopWatch = require("Storage").readJSON("mystopwatch.json", true) || {start1: null, elapsed1: null, start2: null, elapsed2: null}; let stopWatch = require("Storage").readJSON("mystopwatch.json", true) || {start1: null, elapsed1: null, buzz1: null, start2: null, elapsed2: null, buzzed2: null};
let saveStopWatch = function() { let saveStopWatch = function() {
require("Storage").writeJSON("mystopwatch.json", stopWatch); require("Storage").writeJSON("mystopwatch.json", stopWatch);
} }
@@ -37,6 +37,14 @@
let Tt1 = (stopWatch.elapsed1 || 0); let Tt1 = (stopWatch.elapsed1 || 0);
if (stopWatch.start1) { if (stopWatch.start1) {
Tt1 += Date.now() - stopWatch.start1; Tt1 += Date.now() - stopWatch.start1;
const fifteenMinutes = 15 * 60 * 1000;
let intervals = Math.floor(Tt1 / fifteenMinutes);
if (intervals > (stopWatch.buzz1 || 0)) {
stopWatch.buzz1 = intervals;
Bangle.buzz(500);
saveStopWatch();
}
} }
let Ttxt1 = timeToText(Tt1); let Ttxt1 = timeToText(Tt1);
@@ -49,6 +57,13 @@
let Tt2 = (stopWatch.elapsed2 || 0); let Tt2 = (stopWatch.elapsed2 || 0);
if (stopWatch.start2) { if (stopWatch.start2) {
Tt2 += Date.now() - stopWatch.start2; Tt2 += Date.now() - stopWatch.start2;
const oneMinute = 60 * 1000;
if (!stopWatch.buzzed2 && Tt2 >= oneMinute) {
stopWatch.buzzed2 = true;
Bangle.buzz(500);
saveStopWatch();
}
} }
let Ttxt2 = timeToText(Tt2); let Ttxt2 = timeToText(Tt2);
@@ -193,6 +208,7 @@
stopWatch.start1 = Date.now(); stopWatch.start1 = Date.now();
if (!stopWatch.elapsed1) { if (!stopWatch.elapsed1) {
stopWatch.elapsed1 = 0; stopWatch.elapsed1 = 0;
stopWatch.buzz1 = 0;
} }
saveStopWatch(); saveStopWatch();
@@ -207,6 +223,7 @@
stopWatch.start2 = Date.now(); stopWatch.start2 = Date.now();
if (!stopWatch.elapsed2) { if (!stopWatch.elapsed2) {
stopWatch.elapsed2 = 0; stopWatch.elapsed2 = 0;
stopWatch.buzzed2 = false;
} }
saveStopWatch(); saveStopWatch();
@@ -233,6 +250,7 @@
let stopSW1 = function() { let stopSW1 = function() {
stopWatch.start1 = null; stopWatch.start1 = null;
stopWatch.elapsed1 = null; stopWatch.elapsed1 = null;
stopWatch.buzz1 = null;
saveStopWatch(); saveStopWatch();
if (!stopWatch.start2) { if (!stopWatch.start2) {
@@ -260,6 +278,7 @@
let stopSW2 = function() { let stopSW2 = function() {
stopWatch.start2 = null; stopWatch.start2 = null;
stopWatch.elapsed2 = null; stopWatch.elapsed2 = null;
stopWatch.buzzed2 = null;
saveStopWatch(); saveStopWatch();
if (!stopWatch.start1) { if (!stopWatch.start1) {
@@ -403,7 +422,7 @@
Bangle.removeListener('twist', handleTwist); Bangle.removeListener('twist', handleTwist);
if (drawTimer) clearTimeout(drawTimer); if (drawTimer) clearTimeout(drawTimer);
drawTimer = undefined; drawTimer = undefined;
if (stopWatchTimer) clearTimeout(stopWatchTimer); if (stopWatchTimer) clearInterval(stopWatchTimer);
stopWatchTimer = undefined; stopWatchTimer = undefined;
paintFace = undefined; // http request may resolve after font's been unloaded, so unset paintFace = undefined; // http request may resolve after font's been unloaded, so unset