Skip to content

Commit 318656a

Browse files
authored
Merge pull request #3942 from bobrippling/workaround/promenu-2v27
promenu: workaround `setUI` touch handler bug (2v26/2v27)
2 parents 9360190 + 2c51bc8 commit 318656a

File tree

4 files changed

+67
-21
lines changed

4 files changed

+67
-21
lines changed

apps/promenu/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
0.12: Fix bug where settings would behave as if all were set to false
1717
0.13: Update to new touch-event handling
1818
0.14: Fix bug in handling changes to `Bangle.appRect`
19+
0.15: Workaround bug in 2v26/2v27 firmware

apps/promenu/bootb2.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ var _a, _b;
22
var prosettings = (require("Storage").readJSON("promenu.settings.json", true) || {});
33
(_a = prosettings.naturalScroll) !== null && _a !== void 0 ? _a : (prosettings.naturalScroll = false);
44
(_b = prosettings.wrapAround) !== null && _b !== void 0 ? _b : (prosettings.wrapAround = true);
5-
E.showMenu = function (items) {
5+
E.showMenu = (function (items) {
6+
if (items == null) {
7+
g.clearRect(Bangle.appRect);
8+
return Bangle.setUI();
9+
}
610
var RectRnd = function (x1, y1, x2, y2, r) {
711
var pp = [];
812
pp.push.apply(pp, g.quadraticBezier([x2 - r, y1, x2, y1, x2, y1 + r]));
@@ -122,7 +126,6 @@ E.showMenu = function (items) {
122126
nameScroll_1 = 0;
123127
}, 300, name, v, item, idx, x, iy);
124128
}
125-
g.setColor(g.theme.fg);
126129
iy += fontHeight;
127130
idx++;
128131
};
@@ -204,19 +207,31 @@ E.showMenu = function (items) {
204207
else
205208
l.select(evt);
206209
};
207-
Bangle.setUI({
210+
var touchcb = (function (_button, xy) {
211+
cb(void 0, xy);
212+
});
213+
var uiopts = {
208214
mode: "updown",
209215
back: back,
210216
remove: function () {
211217
var _a;
212218
if (nameScroller)
213219
clearInterval(nameScroller);
214220
Bangle.removeListener("swipe", onSwipe);
221+
if (setUITouch)
222+
Bangle.removeListener("touch", touchcb);
215223
(_a = options.remove) === null || _a === void 0 ? void 0 : _a.call(options);
216224
},
217-
touch: (function (_button, xy) {
218-
cb(void 0, xy);
219-
}),
220-
}, cb);
225+
};
226+
var setUITouch = process.env.VERSION >= "2v26";
227+
if (!setUITouch) {
228+
uiopts.touch = touchcb;
229+
}
230+
Bangle.setUI(uiopts, cb);
231+
if (setUITouch) {
232+
Bangle.removeListener("touch", Bangle.touchHandler);
233+
delete Bangle.touchHandler;
234+
Bangle.on("touch", touchcb);
235+
}
221236
return l;
222-
};
237+
});

apps/promenu/bootb2.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ const prosettings = (require("Storage").readJSON("promenu.settings.json", true)
1313
prosettings.naturalScroll ??= false;
1414
prosettings.wrapAround ??= true;
1515

16-
E.showMenu = (items?: Menu): MenuInstance => {
16+
E.showMenu = ((items?: Menu): MenuInstance | void => {
17+
if(items == null){
18+
g.clearRect(Bangle.appRect);
19+
return Bangle.setUI();
20+
}
21+
1722
const RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => {
1823
const pp = [];
1924
pp.push(...g.quadraticBezier([x2 - r, y1, x2, y1, x2, y1 + r]));
@@ -167,7 +172,6 @@ E.showMenu = (items?: Menu): MenuInstance => {
167172
}, 300, name, v, item, idx, x, iy);
168173
}
169174

170-
g.setColor(g.theme.fg);
171175
iy += fontHeight;
172176
idx++;
173177
}
@@ -252,21 +256,47 @@ E.showMenu = (items?: Menu): MenuInstance => {
252256
else l.select(evt);
253257
};
254258

255-
Bangle.setUI({
259+
const touchcb = ((_button, xy) => {
260+
// since we've specified options.touch,
261+
// we need to pass through all taps since the default
262+
// touchHandler isn't installed in setUI
263+
cb(void 0, xy);
264+
}) satisfies TouchCallback;
265+
266+
const uiopts = {
256267
mode: "updown",
257-
back,
268+
back: back as () => void,
258269
remove: () => {
259270
if (nameScroller) clearInterval(nameScroller);
260271
Bangle.removeListener("swipe", onSwipe);
272+
if(setUITouch)
273+
Bangle.removeListener("touch", touchcb);
261274
options.remove?.();
262275
},
263-
touch: ((_button, xy) => {
264-
// since we've specified options.touch,
265-
// we need to pass through all taps since the default
266-
// touchHandler isn't installed in setUI
267-
cb(void 0, xy);
268-
}) satisfies TouchCallback,
269-
} as SetUIArg<"updown">, cb);
276+
} satisfies SetUIArg<"updown">;
277+
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
282+
(uiopts as any).touch = touchcb;
283+
}
284+
285+
Bangle.setUI(uiopts, cb);
286+
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:
293+
// - https://github.com/espruino/Espruino/issues/2648
294+
// - https://github.com/orgs/espruino/discussions/7697#discussioncomment-13782299
295+
Bangle.removeListener("touch", (Bangle as any).touchHandler);
296+
delete (Bangle as any).touchHandler;
297+
298+
Bangle.on("touch", touchcb);
299+
}
270300

271301
return l;
272-
};
302+
}) as typeof E.showMenu;

apps/promenu/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "promenu",
33
"name": "Pro Menu",
4-
"version": "0.14",
4+
"version": "0.15",
55
"description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.",
66
"icon": "icon.png",
77
"type": "bootloader",

0 commit comments

Comments
 (0)