clock_info: save only on `kill` and `remove`

pull/3263/head
Rob Pilling 2024-03-20 08:07:21 +00:00
parent ffc66c52d2
commit 45a3f7e5d2
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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);