From 192ba32a5d9fa0d04daa6a2d017ce70770f7a367 Mon Sep 17 00:00:00 2001 From: Richard de Boer Date: Thu, 28 May 2020 22:32:53 +0200 Subject: [PATCH 1/2] simpletimer: make BTN2 really return to launcher (only while countdown is not running) --- apps/simpletimer/README.md | 1 + apps/simpletimer/app.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/simpletimer/README.md b/apps/simpletimer/README.md index ebe54dbe5..426942034 100644 --- a/apps/simpletimer/README.md +++ b/apps/simpletimer/README.md @@ -15,4 +15,5 @@ Simple timer, useful when playing board games or cooking - Tap on seconds to increase them one by one - Press BTN3 to reset time to 0 - Press BTN1 to start the timer or reset to the original time +- Press BTN2 to return to the launcher (only while countdown is not running) - When the time is up use the [swipeleft](https://github.com/espruino/BangleApps/tree/master/apps/gesture) gesture to reset the timer diff --git a/apps/simpletimer/app.js b/apps/simpletimer/app.js index 0bd7992e2..8c8890af3 100644 --- a/apps/simpletimer/app.js +++ b/apps/simpletimer/app.js @@ -111,7 +111,6 @@ function reset(value) { state = value === 0 ? "unset" : "set"; } -setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); function addWatch() { clearWatch(); setWatch(changeState, BTN1, { @@ -119,6 +118,16 @@ function addWatch() { repeat: true, edge: "falling" }); + setWatch(() => { + if (state !== "started") { + Bangle.showLauncher(); + }}, + BTN2, + { + repeat: false, + edge: "falling", + }, + ); setWatch( () => { reset(0); From 4ab68eb4112bd86fba7dd39e894208f6d18cdd90 Mon Sep 17 00:00:00 2001 From: Richard de Boer Date: Thu, 28 May 2020 22:29:58 +0200 Subject: [PATCH 2/2] simpletimer: remember last set time --- apps.json | 7 ++++++- apps/simpletimer/ChangeLog | 1 + apps/simpletimer/app.js | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps.json b/apps.json index 5eede9c05..9779ba5a2 100644 --- a/apps.json +++ b/apps.json @@ -1634,7 +1634,7 @@ "id": "simpletimer", "name": "Timer", "icon": "app.png", - "version": "0.03", + "version": "0.04", "description": "Simple timer, useful when playing board games or cooking", "tags": "timer", "readme": "README.md", @@ -1659,6 +1659,11 @@ "url": "app-icon.js", "evaluate": true } + ], + "data": [ + { + "name": "simpletimer.json" + } ] }, { diff --git a/apps/simpletimer/ChangeLog b/apps/simpletimer/ChangeLog index 3f8d98248..b9a839e7d 100644 --- a/apps/simpletimer/ChangeLog +++ b/apps/simpletimer/ChangeLog @@ -1,3 +1,4 @@ 0.01: Initial version 0.02: Reset with gesture 0.03: BTN2 to open launcher +0.04: Remember last set time \ No newline at end of file diff --git a/apps/simpletimer/app.js b/apps/simpletimer/app.js index 8c8890af3..041535998 100644 --- a/apps/simpletimer/app.js +++ b/apps/simpletimer/app.js @@ -2,6 +2,7 @@ let counter = 0; let setValue = 0; let counterInterval; let state; +let saved = require("Storage").readJSON("simpletimer.json",true) || {}; const DEBOUNCE = 50; @@ -61,6 +62,8 @@ function clearIntervals() { function set(delta) { if (state === "started") return; counter += delta; + saved.counter = counter; + require("Storage").write("simpletimer.json", saved); if (state === "unset") { state = "set"; } @@ -160,5 +163,5 @@ Bangle.on("aiGesture", gesture => { if (gesture === "swipeleft" && state === "stopped") reset(0); }); -reset(0); +reset(saved.counter || 0); addWatch();