From bb2e54be8dbca91b92b575fc7956c910e92bea88 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 8 Feb 2025 00:21:05 +0100 Subject: [PATCH 01/14] twenties: refactor to use sched library --- apps/twenties/ChangeLog | 1 + apps/twenties/boot.js | 37 +++++------------------------- apps/twenties/lib.js | 45 +++++++++++++++++++++++++++++++++++++ apps/twenties/metadata.json | 7 ++++-- 4 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 apps/twenties/lib.js diff --git a/apps/twenties/ChangeLog b/apps/twenties/ChangeLog index 3381ef6a9f..fc8759718c 100644 --- a/apps/twenties/ChangeLog +++ b/apps/twenties/ChangeLog @@ -4,3 +4,4 @@ 0.04: Convert to boot code 0.05: Improve energy efficiency 0.06: Align with whole thirds of the hour. +0.07: Refactor to use the scheduling library. diff --git a/apps/twenties/boot.js b/apps/twenties/boot.js index 1b55a577fe..7e837e243e 100644 --- a/apps/twenties/boot.js +++ b/apps/twenties/boot.js @@ -1,31 +1,6 @@ -(() => { - const LOOP_INTERVAL = 1.2e6; // 20 minutes - const BUZZ_INTERVAL = 2e4; // 20 seconds - - const isWorkTime = (d) => - d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; - - const scheduleNext = () => { - const now = new Date(); - if (isWorkTime(now)) { - Bangle.buzz().then(() => setTimeout(Bangle.buzz, BUZZ_INTERVAL)); - setTimeout(scheduleNext, LOOP_INTERVAL); - } else { - const next = new Date(now); - next.setHours(8, 0, 0, 0); - while (!isWorkTime(next)) next.setDate(next.getDate() + 1); - setTimeout(scheduleNext, next - now); - } - }; - - // Align so we fire at whole hour, 20 min past and 40 min past - not at arbitrary times. - const TIME_AT_BOOT = new Date(); - const TIME_SINCE_WHOLE_THIRD_OF_HOUR = (TIME_AT_BOOT.getMinutes() % 20) * 6e4 + TIME_AT_BOOT.getSeconds() * 1e3; - setTimeout(scheduleNext, - LOOP_INTERVAL - TIME_SINCE_WHOLE_THIRD_OF_HOUR); - // Make sure we don't miss the 2nd buzz after 20 seconds if we rebooted during that interval. - if (TIME_SINCE_WHOLE_THIRD_OF_HOUR <= BUZZ_INTERVAL) { - setTimeout(Bangle.buzz, - BUZZ_INTERVAL - TIME_SINCE_WHOLE_THIRD_OF_HOUR); - } -})(); +{ // This boot script is deleted once the companion alarm is set up. + // The app will continue working by having the alarm rearm itself until + // the app is uninstalled. +let alarms = require("Storage").readJSON("sched.json", 1) || []; +if (!alarms.includes(a => a.id === "twenties")) {require("twenties").setup(alarms);} +} diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js new file mode 100644 index 0000000000..697edade0c --- /dev/null +++ b/apps/twenties/lib.js @@ -0,0 +1,45 @@ +{ // this code is called from `twenties.boot.js` in a scope where the `alarms` variable is defined. + + exports.getTimeAtNextBuzz = () => { + const isWorkTime = (d) => + d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; + const NOW = new Date(); + let timeAtNextBuzz = 8 * 3600000; + if (isWorkTime(NOW)) { + timeAtNextBuzz = NOW.getHours() * 3600000 + + (NOW.getMinutes() + (20 - NOW.getMinutes() % 20)) * 60000; + } + return timeAtNextBuzz; + } + + const S = require("sched"); + + exports.buzzRearmOrDeleteAlarm = function () { + try { // Verify that twenties is still installed. If not delete its alarm. + require("twenties"); + } catch (e) { + S.setAlarm("twenties", undefined); + S.reload(); + return + } + Bangle.buzz() + let twentiesAlarm = S.getAlarm("twenties"); + twentiesAlarm.t = exports.getTimeAtNextBuzz(); + S.setAlarm("twenties", twentiesAlarm); + } + + exports.setup = function (alarms) { + const TIME_AT_NEXT_BUZZ = exports.getTimeAtNextBuzz() + alarms.push({ + id: "twenties", + on: true, + t: TIME_AT_NEXT_BUZZ, + dow: 0b0111110, + hidden: true, + js: "require('twenties').buzzRearmOrDeleteAlarm()" + }); + S.setAlarms(alarms); + S.reload(); + require("Storage").erase("twenties.boot.js"); + } +} diff --git a/apps/twenties/metadata.json b/apps/twenties/metadata.json index 62b12d1401..12c20a7a9e 100644 --- a/apps/twenties/metadata.json +++ b/apps/twenties/metadata.json @@ -2,7 +2,7 @@ "id": "twenties", "name": "Twenties", "shortName": "Twenties", - "version": "0.06", + "version": "0.07", "description": "Buzzes every 20m to stand / sit and look 20ft away for 20s.", "icon": "app.png", "type": "bootloader", @@ -11,5 +11,8 @@ "supports": ["BANGLEJS", "BANGLEJS2"], "allow_emulator": true, "readme": "README.md", - "storage": [{ "name": "twenties.boot.js", "url": "boot.js" }] + "storage": [ + { "name": "twenties.boot.js", "url": "boot.js" }, + { "name": "twenties", "url": "lib.js" } + ] } From 785c349f242e7b201f2034ac4dee8ccfbace2884 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 23 May 2026 02:03:56 +0200 Subject: [PATCH 02/14] twenties: set group attribute to "Hidden" --- apps/twenties/lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 697edade0c..5c8d478bec 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -36,6 +36,7 @@ t: TIME_AT_NEXT_BUZZ, dow: 0b0111110, hidden: true, + group: "Hidden", js: "require('twenties').buzzRearmOrDeleteAlarm()" }); S.setAlarms(alarms); From b07c298474781967724abf3c3701d4135b7357d1 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 23 May 2026 02:34:57 +0200 Subject: [PATCH 03/14] twenties: fix add back the 20 second look away buzz interval --- apps/twenties/lib.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 5c8d478bec..e0b373bb4c 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -3,13 +3,21 @@ exports.getTimeAtNextBuzz = () => { const isWorkTime = (d) => d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; + const isLookAwayTime = (d) => { + d.getMinutes() % 20 === 0 && d.getseconds < 20 + } const NOW = new Date(); - let timeAtNextBuzz = 8 * 3600000; + let t = 8 * 3600000; if (isWorkTime(NOW)) { - timeAtNextBuzz = NOW.getHours() * 3600000 + - (NOW.getMinutes() + (20 - NOW.getMinutes() % 20)) * 60000; + if (isLookAwayTime(NOW)) { + t = NOW.getHours() * 3600000 + + NOW.getMinutes() * 60000 + 20 * 1000; + } else { + t = NOW.getHours() * 3600000 + + (NOW.getMinutes() + (20 - NOW.getMinutes() % 20)) * 60000; + } } - return timeAtNextBuzz; + return t; } const S = require("sched"); @@ -20,12 +28,13 @@ } catch (e) { S.setAlarm("twenties", undefined); S.reload(); - return + return; } Bangle.buzz() let twentiesAlarm = S.getAlarm("twenties"); twentiesAlarm.t = exports.getTimeAtNextBuzz(); S.setAlarm("twenties", twentiesAlarm); + S.setTimer() } exports.setup = function (alarms) { From d0c473eb37705555462f090916e7c63222bead78 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 11:21:48 +0200 Subject: [PATCH 04/14] twenties: fix typo re `Date.getSeconds()` --- apps/twenties/lib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index e0b373bb4c..9fe7c0358c 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -1,10 +1,10 @@ -{ // this code is called from `twenties.boot.js` in a scope where the `alarms` variable is defined. +{ exports.getTimeAtNextBuzz = () => { const isWorkTime = (d) => d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; const isLookAwayTime = (d) => { - d.getMinutes() % 20 === 0 && d.getseconds < 20 + d.getMinutes() % 20 === 0 && d.getSeconds() < 20 } const NOW = new Date(); let t = 8 * 3600000; From 06dddfe5548536d3a271468607e8ed72ef91d3db Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 11:34:45 +0200 Subject: [PATCH 05/14] twenties: fix uninstall logic --- apps/twenties/lib.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 9fe7c0358c..3f9b843c5b 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -22,21 +22,24 @@ const S = require("sched"); - exports.buzzRearmOrDeleteAlarm = function () { - try { // Verify that twenties is still installed. If not delete its alarm. - require("twenties"); - } catch (e) { - S.setAlarm("twenties", undefined); - S.reload(); - return; - } - Bangle.buzz() + exports.buzzAndRearm = function () { + Bangle.buzz(); let twentiesAlarm = S.getAlarm("twenties"); twentiesAlarm.t = exports.getTimeAtNextBuzz(); S.setAlarm("twenties", twentiesAlarm); - S.setTimer() + S.setTimer(); } + // If twenties is not installed anymore the alarm is deleted (catch block). Otherwise buzz and rearm as usual (try block). + const JS_BUZZ_REARM_OR_DELETE_ALARM = `{ + try { + require('twenties').buzzAndRearm(); + } catch(e) { + S.setAlarm("twenties", undefined); + S.reload(); + } + }` + exports.setup = function (alarms) { const TIME_AT_NEXT_BUZZ = exports.getTimeAtNextBuzz() alarms.push({ @@ -46,7 +49,7 @@ dow: 0b0111110, hidden: true, group: "Hidden", - js: "require('twenties').buzzRearmOrDeleteAlarm()" + js: JS_BUZZ_REARM_OR_DELETE_ALARM }); S.setAlarms(alarms); S.reload(); From b774c6c906ed92adc38ae58416e7d58b34be8c3f Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 11:51:41 +0200 Subject: [PATCH 06/14] twenties: fix arrow function --- apps/twenties/lib.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 3f9b843c5b..60fde2f4a9 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -3,9 +3,8 @@ exports.getTimeAtNextBuzz = () => { const isWorkTime = (d) => d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; - const isLookAwayTime = (d) => { - d.getMinutes() % 20 === 0 && d.getSeconds() < 20 - } + const isLookAwayTime = (d) => + d.getMinutes() % 20 === 0 && d.getSeconds() < 20; const NOW = new Date(); let t = 8 * 3600000; if (isWorkTime(NOW)) { From 597095fdd64034e90e9a8f37dd7387e3ea5837a3 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 13:09:08 +0200 Subject: [PATCH 07/14] twenties: fix 20 second buzz interval (hopefully) --- apps/twenties/boot.js | 2 +- apps/twenties/lib.js | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/twenties/boot.js b/apps/twenties/boot.js index 7e837e243e..91a1a24990 100644 --- a/apps/twenties/boot.js +++ b/apps/twenties/boot.js @@ -2,5 +2,5 @@ // The app will continue working by having the alarm rearm itself until // the app is uninstalled. let alarms = require("Storage").readJSON("sched.json", 1) || []; -if (!alarms.includes(a => a.id === "twenties")) {require("twenties").setup(alarms);} +if (!alarms.includes(a => a.id === "twenties")) {require("twenties").setup();} } diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 60fde2f4a9..ab69b8fd9d 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -7,6 +7,8 @@ d.getMinutes() % 20 === 0 && d.getSeconds() < 20; const NOW = new Date(); let t = 8 * 3600000; + print(NOW); + print(NOW.getSeconds()); if (isWorkTime(NOW)) { if (isLookAwayTime(NOW)) { t = NOW.getHours() * 3600000 + @@ -17,41 +19,40 @@ } } return t; - } + }; const S = require("sched"); exports.buzzAndRearm = function () { + print("buzz"); Bangle.buzz(); let twentiesAlarm = S.getAlarm("twenties"); twentiesAlarm.t = exports.getTimeAtNextBuzz(); S.setAlarm("twenties", twentiesAlarm); - S.setTimer(); - } + }; // If twenties is not installed anymore the alarm is deleted (catch block). Otherwise buzz and rearm as usual (try block). const JS_BUZZ_REARM_OR_DELETE_ALARM = `{ try { require('twenties').buzzAndRearm(); + // require("twenties").setup(); // For DEBUGGING as to regenerate the javascript string to evaluate in the alarm. } catch(e) { - S.setAlarm("twenties", undefined); - S.reload(); + require("sched").setAlarm("twenties", undefined); + require("sched").reload(); + throw(e); } - }` + }`; - exports.setup = function (alarms) { - const TIME_AT_NEXT_BUZZ = exports.getTimeAtNextBuzz() - alarms.push({ - id: "twenties", + exports.setup = function () { + S.setAlarm("twenties", { on: true, - t: TIME_AT_NEXT_BUZZ, + t: exports.getTimeAtNextBuzz(), dow: 0b0111110, hidden: true, group: "Hidden", js: JS_BUZZ_REARM_OR_DELETE_ALARM }); - S.setAlarms(alarms); S.reload(); require("Storage").erase("twenties.boot.js"); - } + }; } From da9584ac9279e8f4819ea403ce6a025e419a2d3a Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 16:01:01 +0200 Subject: [PATCH 08/14] twenties: fix so alarms are reloaded whence modified. --- apps/twenties/lib.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index ab69b8fd9d..23f0ef4838 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -7,8 +7,6 @@ d.getMinutes() % 20 === 0 && d.getSeconds() < 20; const NOW = new Date(); let t = 8 * 3600000; - print(NOW); - print(NOW.getSeconds()); if (isWorkTime(NOW)) { if (isLookAwayTime(NOW)) { t = NOW.getHours() * 3600000 + @@ -24,11 +22,11 @@ const S = require("sched"); exports.buzzAndRearm = function () { - print("buzz"); Bangle.buzz(); let twentiesAlarm = S.getAlarm("twenties"); twentiesAlarm.t = exports.getTimeAtNextBuzz(); S.setAlarm("twenties", twentiesAlarm); + S.reload(); }; // If twenties is not installed anymore the alarm is deleted (catch block). Otherwise buzz and rearm as usual (try block). From 2cfb8abdae8e396cf02ae59de2b7ee2622caa26d Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 16:43:13 +0200 Subject: [PATCH 09/14] twenties: rework logic re deleting the app and its alarms --- apps/twenties/boot.js | 4 ++-- apps/twenties/lib.js | 28 +++++++--------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/apps/twenties/boot.js b/apps/twenties/boot.js index 91a1a24990..8450b7e293 100644 --- a/apps/twenties/boot.js +++ b/apps/twenties/boot.js @@ -1,6 +1,6 @@ { // This boot script is deleted once the companion alarm is set up. // The app will continue working by having the alarm rearm itself until // the app is uninstalled. -let alarms = require("Storage").readJSON("sched.json", 1) || []; -if (!alarms.includes(a => a.id === "twenties")) {require("twenties").setup();} + require("twenties").setup(); + require("Storage").erase("twenties.boot.js"); } diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 23f0ef4838..f7cec6da78 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -1,5 +1,4 @@ { - exports.getTimeAtNextBuzz = () => { const isWorkTime = (d) => d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18; @@ -19,27 +18,14 @@ return t; }; - const S = require("sched"); - - exports.buzzAndRearm = function () { + exports.buzzAndSetup = function () { Bangle.buzz(); - let twentiesAlarm = S.getAlarm("twenties"); - twentiesAlarm.t = exports.getTimeAtNextBuzz(); - S.setAlarm("twenties", twentiesAlarm); - S.reload(); + exports.setup(); }; - // If twenties is not installed anymore the alarm is deleted (catch block). Otherwise buzz and rearm as usual (try block). - const JS_BUZZ_REARM_OR_DELETE_ALARM = `{ - try { - require('twenties').buzzAndRearm(); - // require("twenties").setup(); // For DEBUGGING as to regenerate the javascript string to evaluate in the alarm. - } catch(e) { - require("sched").setAlarm("twenties", undefined); - require("sched").reload(); - throw(e); - } - }`; + const JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP = `require("sched").setAlarm("twenties", undefined); require("sched").reload(); require('twenties').buzzAndSetup();`; + + const S = require("sched"); exports.setup = function () { S.setAlarm("twenties", { @@ -48,9 +34,9 @@ dow: 0b0111110, hidden: true, group: "Hidden", - js: JS_BUZZ_REARM_OR_DELETE_ALARM + del: true, + js: JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP }); S.reload(); - require("Storage").erase("twenties.boot.js"); }; } From 5383eb8e690a4bdbb3beeb6c3ce81d584b2604e5 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 17:21:27 +0200 Subject: [PATCH 10/14] twenties: drop a schedule reload --- apps/twenties/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index f7cec6da78..ddf88d128f 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -23,7 +23,7 @@ exports.setup(); }; - const JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP = `require("sched").setAlarm("twenties", undefined); require("sched").reload(); require('twenties').buzzAndSetup();`; + const JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP = `require("sched").setAlarm("twenties", undefined); require('twenties').buzzAndSetup();`; const S = require("sched"); From a3b51cf7afcc9456c2e88ee70d31e69cc7fb730b Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 18:18:46 +0200 Subject: [PATCH 11/14] twenties: drop del attribute from alarm --- apps/twenties/lib.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index ddf88d128f..f9b3b8d452 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -34,7 +34,6 @@ dow: 0b0111110, hidden: true, group: "Hidden", - del: true, js: JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP }); S.reload(); From 70e7abf422a1c08c4d62dd8ccbaa436eb4cb4779 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 25 May 2026 22:40:54 +0200 Subject: [PATCH 12/14] twenties: fix working around sched library peculiarity setting an alarm at a time that had already occurred today would fire immediately instead of be scheduled for tomorrow. --- apps/twenties/lib.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index f9b3b8d452..57c311b884 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -15,6 +15,7 @@ (NOW.getMinutes() + (20 - NOW.getMinutes() % 20)) * 60000; } } + print(t); return t; }; @@ -28,14 +29,23 @@ const S = require("sched"); exports.setup = function () { - S.setAlarm("twenties", { + const TIME_AT_NEXT_BUZZ = exports.getTimeAtNextBuzz(); + const TIME_AT_SETUP = new Date(); + let alarm = { on: true, - t: exports.getTimeAtNextBuzz(), + t: TIME_AT_NEXT_BUZZ, dow: 0b0111110, hidden: true, group: "Hidden", js: JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP - }); + }; + if ( TIME_AT_NEXT_BUZZ < + TIME_AT_SETUP.getHours() * 3600000 + + TIME_AT_SETUP.getMinutes() * 60000 + + TIME_AT_SETUP.getSeconds() * 1000 ) { // FIXME: this is done to work around a behavior in sched library. I think that is maybe a :BUG: that we should fix there. But unsure. It's around https://github.com/espruino/BangleApps/blob/master/apps/sched/boot.js#L21-L21 + alarm.last = Date().getDate(); + } + S.setAlarm("twenties", alarm); S.reload(); }; } From e3c8afc0d150a9add1b34dba465f74f1091f8a60 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 28 May 2026 22:35:16 +0200 Subject: [PATCH 13/14] twenties: fix boot script not running before being deleted (I think that was the problem at least.) --- apps/twenties/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/twenties/boot.js b/apps/twenties/boot.js index 8450b7e293..295bf42a8d 100644 --- a/apps/twenties/boot.js +++ b/apps/twenties/boot.js @@ -2,5 +2,5 @@ // The app will continue working by having the alarm rearm itself until // the app is uninstalled. require("twenties").setup(); - require("Storage").erase("twenties.boot.js"); + setTimeout(require("Storage").erase, 1000, "twenties.boot.js"); } From 75999de16a2ec55ceed7af8e5e5dea3bbd5c06a2 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Fri, 29 May 2026 08:35:22 +0200 Subject: [PATCH 14/14] twenties: try to fix interference with `edgeclk` drawing time --- apps/twenties/lib.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/twenties/lib.js b/apps/twenties/lib.js index 57c311b884..e33ce464a2 100644 --- a/apps/twenties/lib.js +++ b/apps/twenties/lib.js @@ -20,8 +20,10 @@ }; exports.buzzAndSetup = function () { - Bangle.buzz(); - exports.setup(); + setTimeout(() => { // Timeout to try and not interfere with `edgeclk` redrawing the time. + Bangle.buzz(); + exports.setup(); + }, 10) }; const JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP = `require("sched").setAlarm("twenties", undefined); require('twenties').buzzAndSetup();`; @@ -39,10 +41,10 @@ group: "Hidden", js: JS_DELETE_ALARM_THEN_BUZZ_AND_SETUP }; - if ( TIME_AT_NEXT_BUZZ < + if (TIME_AT_NEXT_BUZZ < TIME_AT_SETUP.getHours() * 3600000 + TIME_AT_SETUP.getMinutes() * 60000 + - TIME_AT_SETUP.getSeconds() * 1000 ) { // FIXME: this is done to work around a behavior in sched library. I think that is maybe a :BUG: that we should fix there. But unsure. It's around https://github.com/espruino/BangleApps/blob/master/apps/sched/boot.js#L21-L21 + TIME_AT_SETUP.getSeconds() * 1000) { // FIXME: this is done to work around a behavior in sched library. I think that is maybe a :BUG: that we should fix there. But unsure. It's around https://github.com/espruino/BangleApps/blob/master/apps/sched/boot.js#L21-L21 alarm.last = Date().getDate(); } S.setAlarm("twenties", alarm);