From 5be18f426144ffd8c8e6779e0d906cb4aa08b5c2 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 16 Mar 2024 08:47:05 +0000 Subject: [PATCH 1/5] clock_info: expose a save (settings) method --- apps/clock_info/ChangeLog | 1 + apps/clock_info/lib.js | 11 +++++++---- apps/clock_info/metadata.json | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/clock_info/ChangeLog b/apps/clock_info/ChangeLog index 97e62e238..26fc20a51 100644 --- a/apps/clock_info/ChangeLog +++ b/apps/clock_info/ChangeLog @@ -7,3 +7,4 @@ 0.06: When >1 clockinfo, swiping one back tries to ensure they don't display the same thing 0.07: Developer tweak: clkinfo load errors are emitted 0.08: Pass options to show(), hide() and run(), and add focus() and blur() item methods +0.09: Expose a save() method on options diff --git a/apps/clock_info/lib.js b/apps/clock_info/lib.js index d35ac5cf0..e435be6cc 100644 --- a/apps/clock_info/lib.js +++ b/apps/clock_info/lib.js @@ -224,6 +224,12 @@ exports.addInteractive = function(menu, options) { options.menuB = b; } } + options.save = () => { + // save the currently showing clock_info + const settings = exports.loadSettings(); + settings.apps[appName] = {a:options.menuA, b:options.menuB}; + require("Storage").writeJSON("clock_info.json",settings); + }; if (options.menuA===undefined) options.menuA = 0; if (options.menuB===undefined) options.menuB = Math.min(exports.loadCount, menu[options.menuA].items.length)-1; @@ -276,10 +282,7 @@ exports.addInteractive = function(menu, options) { oldMenuItem.removeAllListeners("draw"); menuShowItem(menu[options.menuA].items[options.menuB]); } - // save the currently showing clock_info - let settings = exports.loadSettings(); - settings.apps[appName] = {a:options.menuA,b:options.menuB}; - require("Storage").writeJSON("clock_info.json",settings); + options.save(); // On 2v18+ firmware we can stop other event handlers from being executed since we handled this E.stopEventPropagation&&E.stopEventPropagation(); } diff --git a/apps/clock_info/metadata.json b/apps/clock_info/metadata.json index 351425a8f..d2a5540e1 100644 --- a/apps/clock_info/metadata.json +++ b/apps/clock_info/metadata.json @@ -1,7 +1,7 @@ { "id": "clock_info", "name": "Clock Info Module", "shortName": "Clock Info", - "version":"0.08", + "version":"0.09", "description": "A library used by clocks to provide extra information on the clock face (Altitude, BPM, etc)", "icon": "app.png", "type": "module", From 16c07f24a5380f329c48f2db4bf41d7580e506bd Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 16 Mar 2024 08:48:21 +0000 Subject: [PATCH 2/5] smpltmr: save clkinfo when changing menu --- apps/smpltmr/ChangeLog | 1 + apps/smpltmr/clkinfo.js | 1 + apps/smpltmr/metadata.json | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/smpltmr/ChangeLog b/apps/smpltmr/ChangeLog index 2c073ff43..dd6c00af9 100644 --- a/apps/smpltmr/ChangeLog +++ b/apps/smpltmr/ChangeLog @@ -7,3 +7,4 @@ 0.07: Update clock_info to avoid a redraw 0.08: Timer ClockInfo now updates once a minute 0.09: Timer ClockInfo resets to timer menu when blurred +0.10: Timer ClockInfo saves clkinfo settings when changing menu diff --git a/apps/smpltmr/clkinfo.js b/apps/smpltmr/clkinfo.js index a7a6bf71b..8ad9809ce 100644 --- a/apps/smpltmr/clkinfo.js +++ b/apps/smpltmr/clkinfo.js @@ -73,6 +73,7 @@ const restoreMainItem = function(clkinfo) { clkinfo.menuB = 0; + clkinfo.save(); // clock info redraws after this }; diff --git a/apps/smpltmr/metadata.json b/apps/smpltmr/metadata.json index 98affcfe6..2f33f07b9 100644 --- a/apps/smpltmr/metadata.json +++ b/apps/smpltmr/metadata.json @@ -2,7 +2,7 @@ "id": "smpltmr", "name": "Simple Timer", "shortName": "Simple Timer", - "version": "0.09", + "version": "0.10", "description": "A very simple app to start a timer.", "icon": "app.png", "tags": "tool,alarm,timer,clkinfo", From ffc66c52d269824c287cc1ac21a560550ef3e669 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 20 Mar 2024 08:04:59 +0000 Subject: [PATCH 3/5] Revert "smpltmr: save clkinfo when changing menu" This reverts commit 16c07f24a5380f329c48f2db4bf41d7580e506bd. --- apps/smpltmr/ChangeLog | 1 - apps/smpltmr/clkinfo.js | 1 - apps/smpltmr/metadata.json | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/smpltmr/ChangeLog b/apps/smpltmr/ChangeLog index dd6c00af9..2c073ff43 100644 --- a/apps/smpltmr/ChangeLog +++ b/apps/smpltmr/ChangeLog @@ -7,4 +7,3 @@ 0.07: Update clock_info to avoid a redraw 0.08: Timer ClockInfo now updates once a minute 0.09: Timer ClockInfo resets to timer menu when blurred -0.10: Timer ClockInfo saves clkinfo settings when changing menu diff --git a/apps/smpltmr/clkinfo.js b/apps/smpltmr/clkinfo.js index 8ad9809ce..a7a6bf71b 100644 --- a/apps/smpltmr/clkinfo.js +++ b/apps/smpltmr/clkinfo.js @@ -73,7 +73,6 @@ const restoreMainItem = function(clkinfo) { clkinfo.menuB = 0; - clkinfo.save(); // clock info redraws after this }; diff --git a/apps/smpltmr/metadata.json b/apps/smpltmr/metadata.json index 2f33f07b9..98affcfe6 100644 --- a/apps/smpltmr/metadata.json +++ b/apps/smpltmr/metadata.json @@ -2,7 +2,7 @@ "id": "smpltmr", "name": "Simple Timer", "shortName": "Simple Timer", - "version": "0.10", + "version": "0.09", "description": "A very simple app to start a timer.", "icon": "app.png", "tags": "tool,alarm,timer,clkinfo", From 45a3f7e5d20ba6652b930ccb99f5edc7a7155cde Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 20 Mar 2024 08:07:21 +0000 Subject: [PATCH 4/5] clock_info: save only on `kill` and `remove` --- apps/clock_info/ChangeLog | 2 +- apps/clock_info/lib.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/clock_info/ChangeLog b/apps/clock_info/ChangeLog index 26fc20a51..a4c25f995 100644 --- a/apps/clock_info/ChangeLog +++ b/apps/clock_info/ChangeLog @@ -7,4 +7,4 @@ 0.06: When >1 clockinfo, swiping one back tries to ensure they don't display the same thing 0.07: Developer tweak: clkinfo load errors are emitted 0.08: Pass options to show(), hide() and run(), and add focus() and blur() item methods -0.09: Expose a save() method on options +0.09: Save clkinfo settings on kill and remove diff --git a/apps/clock_info/lib.js b/apps/clock_info/lib.js index e435be6cc..cf36f5716 100644 --- a/apps/clock_info/lib.js +++ b/apps/clock_info/lib.js @@ -224,12 +224,13 @@ exports.addInteractive = function(menu, options) { options.menuB = b; } } - options.save = () => { + const save = () => { // save the currently showing clock_info const settings = exports.loadSettings(); settings.apps[appName] = {a:options.menuA, b:options.menuB}; require("Storage").writeJSON("clock_info.json",settings); }; + E.on("kill", save); if (options.menuA===undefined) options.menuA = 0; if (options.menuB===undefined) options.menuB = Math.min(exports.loadCount, menu[options.menuA].items.length)-1; @@ -282,7 +283,6 @@ exports.addInteractive = function(menu, options) { oldMenuItem.removeAllListeners("draw"); menuShowItem(menu[options.menuA].items[options.menuB]); } - options.save(); // On 2v18+ firmware we can stop other event handlers from being executed since we handled this E.stopEventPropagation&&E.stopEventPropagation(); } @@ -336,6 +336,7 @@ exports.addInteractive = function(menu, options) { menuShowItem(menu[options.menuA].items[options.menuB]); // return an object with info that can be used to remove the info options.remove = function() { + save(); Bangle.removeListener("swipe",swipeHandler); if (touchHandler) Bangle.removeListener("touch",touchHandler); if (lockHandler) Bangle.removeListener("lock", lockHandler); From f2c04fab5dc98f997c6b5c04f4854594e46cd292 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 20 Mar 2024 22:26:02 +0000 Subject: [PATCH 5/5] clock_info: remove save() kill handler on remove of clkinfo --- apps/clock_info/lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/clock_info/lib.js b/apps/clock_info/lib.js index cf36f5716..7b4e49b5c 100644 --- a/apps/clock_info/lib.js +++ b/apps/clock_info/lib.js @@ -337,6 +337,7 @@ exports.addInteractive = function(menu, options) { // return an object with info that can be used to remove the info options.remove = function() { save(); + E.removeListener("kill", save); Bangle.removeListener("swipe",swipeHandler); if (touchHandler) Bangle.removeListener("touch",touchHandler); if (lockHandler) Bangle.removeListener("lock", lockHandler);