From 45a3f7e5d20ba6652b930ccb99f5edc7a7155cde Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 20 Mar 2024 08:07:21 +0000 Subject: [PATCH] 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);