From 6edcae393cf856320afffca097a84eae5b12e21a Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 29 May 2023 12:00:48 +0100 Subject: [PATCH] multitimer: allow one-shot alarms (delete after) --- apps/multitimer/ChangeLog | 1 + apps/multitimer/README.md | 1 + apps/multitimer/alarm.js | 8 +++++++- apps/multitimer/app.js | 22 ++++++++++++++-------- apps/multitimer/metadata.json | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/apps/multitimer/ChangeLog b/apps/multitimer/ChangeLog index 9a2ab0ff4..c682077e4 100644 --- a/apps/multitimer/ChangeLog +++ b/apps/multitimer/ChangeLog @@ -1,3 +1,4 @@ 0.01: Initial version 0.02: Update for time_utils module 0.03: Use default Bangle formatter for booleans +0.04: Add "Oneshot" setting to delete an alarm/timer after it sounds diff --git a/apps/multitimer/README.md b/apps/multitimer/README.md index f1e2eb281..4dcc4a8fd 100644 --- a/apps/multitimer/README.md +++ b/apps/multitimer/README.md @@ -2,6 +2,7 @@ With this app, you can set timers and chronographs (stopwatches) and watch them count down/up in real time. You can also set alarms - swipe left or right to switch between the three functions. "Hard mode" is also available for timers and alarms. It will double the number of buzz counts and you will have to swipe the screen five to eight times correctly - make a mistake, and you will need to start over. +"Oneshot" can be set on timers and alarms to have it delete itself once it's sounded. ## WARNING * Editing timers in another app (such as the default Alarm app) is not recommended. Editing alarms should not be a problem (in theory). diff --git a/apps/multitimer/alarm.js b/apps/multitimer/alarm.js index eb1b3b259..8c3b1cdd4 100644 --- a/apps/multitimer/alarm.js +++ b/apps/multitimer/alarm.js @@ -105,7 +105,13 @@ function showAlarm(alarm) { alarm.t = alarm.ot; delete alarm.ot; } - if (!alarm.rp) alarm.on = false; + if (!alarm.rp) { + alarm.on = false; + if (alarm.data.oneshot) { + const i = alarms.indexOf(alarm); + if (i >= 0) alarms.splice(i, 1); + } + } } //reset timer value if (alarm.timer) alarm.timer = alarm.data.ot; diff --git a/apps/multitimer/app.js b/apps/multitimer/app.js index 8832d1a25..b066607be 100644 --- a/apps/multitimer/app.js +++ b/apps/multitimer/app.js @@ -228,8 +228,7 @@ function editTimer(idx, a) { else a = timers[idx]; } if (!a.data) { - a.data = {}; - a.data.hm = false; + a.data = { hm: false, oneshot: false }; } var t = decodeTime(a.timer); @@ -291,10 +290,14 @@ function editTimer(idx, a) { } }, "Hard Mode": { - value: a.data.hm, + value: !!a.data.hm, onchange: v => a.data.hm = v }, "Vibrate": require("buzz_menu").pattern(a.vibrate, v => a.vibrate = v), + "Oneshot": { + value: !!a.data.oneshot, + onchange: v => a.data.oneshot = v + }, "Msg": { value: !a.msg ? "" : a.msg.length > 6 ? a.msg.substring(0, 6)+"..." : a.msg, //menu glitch? setTimeout required here @@ -556,8 +559,7 @@ function editAlarm(idx, a) { else a = require("sched").newDefaultAlarm(); } if (!a.data) { - a.data = {}; - a.data.hm = false; + a.data = { hm: false, oneshot: false }; } var t = decodeTime(a.t); @@ -582,8 +584,8 @@ function editAlarm(idx, a) { var menu = { "": { "title": "Alarm" }, "< Back": () => { - if (a.data.hm == true) a.js = "(require('Storage').read('multitimer.alarm.js') !== undefined) ? load('multitimer.alarm.js') : load('sched.js')"; - if (a.data.hm == false && a.js) delete a.js; + if (a.data.hm || a.data.oneshot) a.js = "(require('Storage').read('multitimer.alarm.js') !== undefined) ? load('multitimer.alarm.js') : load('sched.js')"; + else if (a.js) delete a.js; if (idx >= 0) alarms[alarmIdx[idx]] = a; else alarms.push(a); require("sched").setAlarms(alarms); @@ -617,10 +619,14 @@ function editAlarm(idx, a) { onchange: () => editDOW(a.dow, d=>{a.dow=d;editAlarm(idx,a);}) }, "Hard Mode": { - value: a.data.hm, + value: !!a.data.hm, onchange: v => a.data.hm = v }, "Vibrate": require("buzz_menu").pattern(a.vibrate, v => a.vibrate = v), + "Oneshot": { + value: !!a.data.oneshot, + onchange: v => a.data.oneshot = v + }, "Auto Snooze": { value: a.as, onchange: v => a.as = v diff --git a/apps/multitimer/metadata.json b/apps/multitimer/metadata.json index ee77d2ecb..0c9eddc9e 100644 --- a/apps/multitimer/metadata.json +++ b/apps/multitimer/metadata.json @@ -1,7 +1,7 @@ { "id": "multitimer", "name": "Multi Timer", - "version": "0.03", + "version": "0.04", "description": "Set timers and chronographs (stopwatches) and watch them count down in real time. Pause, create, edit, and delete timers and chronos, and add custom labels/messages. Also sets alarms.", "icon": "app.png", "screenshots": [