Merge pull request #3263 from bobrippling/feat/smpltmr-focus-save

clkinfo: save clock info on `kill`/`remove`
pull/3295/head
Gordon Williams 2024-03-25 10:12:55 +00:00 committed by GitHub
commit 0ff839bc75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -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: Save clkinfo settings on kill and remove

View File

@ -224,6 +224,13 @@ exports.addInteractive = function(menu, options) {
options.menuB = b;
}
}
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;
@ -276,10 +283,6 @@ 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);
// On 2v18+ firmware we can stop other event handlers from being executed since we handled this
E.stopEventPropagation&&E.stopEventPropagation();
}
@ -333,6 +336,8 @@ 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();
E.removeListener("kill", save);
Bangle.removeListener("swipe",swipeHandler);
if (touchHandler) Bangle.removeListener("touch",touchHandler);
if (lockHandler) Bangle.removeListener("lock", lockHandler);

View File

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