Skip to content

Commit 2c51bc8

Browse files
committed
promenu: fix double-render from having two callbacks with "updown"
1 parent c0545cf commit 2c51bc8

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

apps/promenu/bootb2.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ E.showMenu = (function (items) {
126126
nameScroll_1 = 0;
127127
}, 300, name, v, item, idx, x, iy);
128128
}
129-
g.setColor(g.theme.fg);
130129
iy += fontHeight;
131130
idx++;
132131
};
@@ -219,17 +218,19 @@ E.showMenu = (function (items) {
219218
if (nameScroller)
220219
clearInterval(nameScroller);
221220
Bangle.removeListener("swipe", onSwipe);
222-
if (is2v26_27)
221+
if (setUITouch)
223222
Bangle.removeListener("touch", touchcb);
224223
(_a = options.remove) === null || _a === void 0 ? void 0 : _a.call(options);
225224
},
226225
};
227-
var is2v26_27 = process.env.VERSION === "2v26" || process.env.VERSION === "2v27";
228-
if (!is2v26_27) {
226+
var setUITouch = process.env.VERSION >= "2v26";
227+
if (!setUITouch) {
229228
uiopts.touch = touchcb;
230229
}
231230
Bangle.setUI(uiopts, cb);
232-
if (is2v26_27) {
231+
if (setUITouch) {
232+
Bangle.removeListener("touch", Bangle.touchHandler);
233+
delete Bangle.touchHandler;
233234
Bangle.on("touch", touchcb);
234235
}
235236
return l;

apps/promenu/bootb2.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,32 @@ E.showMenu = ((items?: Menu): MenuInstance | void => {
269269
remove: () => {
270270
if (nameScroller) clearInterval(nameScroller);
271271
Bangle.removeListener("swipe", onSwipe);
272-
if(is2v26_27)
272+
if(setUITouch)
273273
Bangle.removeListener("touch", touchcb);
274274
options.remove?.();
275275
},
276276
} satisfies SetUIArg<"updown">;
277277

278-
const is2v26_27 = process.env.VERSION === "2v26" || process.env.VERSION === "2v27";
279-
if (!is2v26_27) {
280-
// no need for workaround
278+
// does setUI install its own touch handler?
279+
const setUITouch = process.env.VERSION >= "2v26";
280+
if (!setUITouch) {
281+
// old firmware, we can use its touch handler - no need for workaround
281282
(uiopts as any).touch = touchcb;
282283
}
283284

284285
Bangle.setUI(uiopts, cb);
285286

286-
if(is2v26_27){
287-
// work around:
287+
if(setUITouch){
288+
// new firmware, remove setUI's touch handler and use just our own to
289+
// avoid `cb` drawing the menu (as part of setUI's touch handler)
290+
// followed by us drawing the menu (as part of our touch handler)
291+
//
292+
// work around details:
288293
// - https://github.com/espruino/Espruino/issues/2648
289294
// - https://github.com/orgs/espruino/discussions/7697#discussioncomment-13782299
295+
Bangle.removeListener("touch", (Bangle as any).touchHandler);
296+
delete (Bangle as any).touchHandler;
297+
290298
Bangle.on("touch", touchcb);
291299
}
292300

0 commit comments

Comments
 (0)