widhid: disable (temporarily) if a menu's shown

pull/2743/head
Rob Pilling 2023-05-10 21:57:33 +01:00
parent 051b417971
commit a9affac57e
2 changed files with 38 additions and 0 deletions

View File

@ -10,9 +10,23 @@
var dragging = false;
var activeTimeout;
var waitForRelease = true;
var menuShown = 0;
var origShowMenu = E.showMenu;
E.showMenu = (function (menu) {
menuShown++;
var origSetUI = Bangle.setUI;
Bangle.setUI = (function (mode, cb) {
menuShown--;
Bangle.setUI = origSetUI;
return origSetUI(mode, cb);
});
return origShowMenu(menu);
});
var onSwipe = (function (_lr, ud) {
if (Bangle.CLKINFO_FOCUS)
return;
if (menuShown)
return;
if (!activeTimeout && ud > 0) {
listen();
Bangle.buzz(20);

View File

@ -12,9 +12,33 @@
let dragging = false;
let activeTimeout: number | undefined;
let waitForRelease = true;
let menuShown = 0;
// If the user shows a menu, we want to temporarily disable ourselves
// We can detect showing of a menu by overriding E.showMenu
// to detect hiding of a menu, we hook setUI, since all menus
// either show other menus, load() or (eventually) call it
// (I hope)
//
// Alternatively we could watch for when Bangle.dragHandler and
// Bangle.swipeHandler get removed from Bangle["#on<event>"]
const origShowMenu = E.showMenu;
E.showMenu = ((menu: Menu): MenuInstance => {
menuShown++;
const origSetUI = Bangle.setUI;
Bangle.setUI = ((mode: unknown, cb: () => void) => {
menuShown--;
Bangle.setUI = origSetUI;
return origSetUI(mode as any, cb);
}) as any;
return origShowMenu(menu);
}) as any;
const onSwipe = ((_lr, ud) => {
if((Bangle as BangleExt).CLKINFO_FOCUS) return;
if(menuShown) return;
if(!activeTimeout && ud! > 0){
listen();