promenu: fix double-render from having two callbacks with "updown"

master
Rob Pilling 2025-07-23 20:54:14 +01:00
parent c0545cf2c2
commit 2c51bc80e5
2 changed files with 20 additions and 11 deletions

View File

@ -126,7 +126,6 @@ E.showMenu = (function (items) {
nameScroll_1 = 0;
}, 300, name, v, item, idx, x, iy);
}
g.setColor(g.theme.fg);
iy += fontHeight;
idx++;
};
@ -219,17 +218,19 @@ E.showMenu = (function (items) {
if (nameScroller)
clearInterval(nameScroller);
Bangle.removeListener("swipe", onSwipe);
if (is2v26_27)
if (setUITouch)
Bangle.removeListener("touch", touchcb);
(_a = options.remove) === null || _a === void 0 ? void 0 : _a.call(options);
},
};
var is2v26_27 = process.env.VERSION === "2v26" || process.env.VERSION === "2v27";
if (!is2v26_27) {
var setUITouch = process.env.VERSION >= "2v26";
if (!setUITouch) {
uiopts.touch = touchcb;
}
Bangle.setUI(uiopts, cb);
if (is2v26_27) {
if (setUITouch) {
Bangle.removeListener("touch", Bangle.touchHandler);
delete Bangle.touchHandler;
Bangle.on("touch", touchcb);
}
return l;

View File

@ -269,24 +269,32 @@ E.showMenu = ((items?: Menu): MenuInstance | void => {
remove: () => {
if (nameScroller) clearInterval(nameScroller);
Bangle.removeListener("swipe", onSwipe);
if(is2v26_27)
if(setUITouch)
Bangle.removeListener("touch", touchcb);
options.remove?.();
},
} satisfies SetUIArg<"updown">;
const is2v26_27 = process.env.VERSION === "2v26" || process.env.VERSION === "2v27";
if (!is2v26_27) {
// no need for workaround
// does setUI install its own touch handler?
const setUITouch = process.env.VERSION >= "2v26";
if (!setUITouch) {
// old firmware, we can use its touch handler - no need for workaround
(uiopts as any).touch = touchcb;
}
Bangle.setUI(uiopts, cb);
if(is2v26_27){
// work around:
if(setUITouch){
// new firmware, remove setUI's touch handler and use just our own to
// avoid `cb` drawing the menu (as part of setUI's touch handler)
// followed by us drawing the menu (as part of our touch handler)
//
// work around details:
// - https://github.com/espruino/Espruino/issues/2648
// - https://github.com/orgs/espruino/discussions/7697#discussioncomment-13782299
Bangle.removeListener("touch", (Bangle as any).touchHandler);
delete (Bangle as any).touchHandler;
Bangle.on("touch", touchcb);
}