widhid: disable all touch events when active
parent
28fe46f77e
commit
a2e9c8db1e
|
|
@ -124,14 +124,41 @@
|
||||||
var toggle = function () { return sendHid(0x10); };
|
var toggle = function () { return sendHid(0x10); };
|
||||||
var up = function () { return sendHid(0x40); };
|
var up = function () { return sendHid(0x40); };
|
||||||
var down = function () { return sendHid(0x80); };
|
var down = function () { return sendHid(0x80); };
|
||||||
|
var touchEvents = {
|
||||||
|
tap: null,
|
||||||
|
gesture: null,
|
||||||
|
aiGesture: null,
|
||||||
|
swipe: null,
|
||||||
|
touch: null,
|
||||||
|
drag: null,
|
||||||
|
stroke: null,
|
||||||
|
};
|
||||||
var suspendOthers = function () {
|
var suspendOthers = function () {
|
||||||
var swipeHandler = Bangle.swipeHandler;
|
for (var event in touchEvents) {
|
||||||
if (swipeHandler)
|
var handlers = Bangle["#on".concat(event)];
|
||||||
Bangle.removeListener("swipe", swipeHandler);
|
if (!handlers)
|
||||||
|
continue;
|
||||||
|
var newEvents = void 0;
|
||||||
|
if (handlers instanceof Array)
|
||||||
|
newEvents = handlers.slice();
|
||||||
|
else
|
||||||
|
newEvents = [handlers];
|
||||||
|
for (var _i = 0, newEvents_1 = newEvents; _i < newEvents_1.length; _i++) {
|
||||||
|
var handler = newEvents_1[_i];
|
||||||
|
Bangle.removeListener(event, handler);
|
||||||
|
}
|
||||||
|
touchEvents[event] = newEvents;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var resumeOthers = function () {
|
var resumeOthers = function () {
|
||||||
var swipeHandler = Bangle.swipeHandler;
|
for (var event in touchEvents) {
|
||||||
if (swipeHandler)
|
var handlers = touchEvents[event];
|
||||||
Bangle.on("swipe", swipeHandler);
|
touchEvents[event] = null;
|
||||||
|
if (handlers)
|
||||||
|
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
|
||||||
|
var handler = handlers_1[_i];
|
||||||
|
Bangle.on(event, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -138,14 +138,48 @@
|
||||||
const up = () => /*DEBUG ? console.log("up") : */ sendHid(0x40);
|
const up = () => /*DEBUG ? console.log("up") : */ sendHid(0x40);
|
||||||
const down = () => /*DEBUG ? console.log("down") : */ sendHid(0x80);
|
const down = () => /*DEBUG ? console.log("down") : */ sendHid(0x80);
|
||||||
|
|
||||||
|
// similarly to the lightswitch app, we tangle with the listener arrays to
|
||||||
|
// disable event handlers
|
||||||
|
type Handler = () => void;
|
||||||
|
const touchEvents: {
|
||||||
|
[key: string]: null | Handler[]
|
||||||
|
} = {
|
||||||
|
tap: null,
|
||||||
|
gesture: null,
|
||||||
|
aiGesture: null,
|
||||||
|
swipe: null,
|
||||||
|
touch: null,
|
||||||
|
drag: null,
|
||||||
|
stroke: null,
|
||||||
|
};
|
||||||
|
|
||||||
const suspendOthers = () => {
|
const suspendOthers = () => {
|
||||||
const swipeHandler = (Bangle as {swipeHandler?: () => void}).swipeHandler;
|
for(const event in touchEvents){
|
||||||
if(swipeHandler)
|
const handlers: Handler[] | Handler | undefined
|
||||||
Bangle.removeListener("swipe", swipeHandler); // swiperclocklaunch
|
= (Bangle as any)[`#on${event}`];
|
||||||
|
|
||||||
|
if(!handlers) continue;
|
||||||
|
|
||||||
|
let newEvents;
|
||||||
|
if(handlers instanceof Array)
|
||||||
|
newEvents = handlers.slice();
|
||||||
|
else
|
||||||
|
newEvents = [handlers /* single fn */];
|
||||||
|
|
||||||
|
for(const handler of newEvents)
|
||||||
|
Bangle.removeListener(event, handler);
|
||||||
|
|
||||||
|
touchEvents[event] = newEvents;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const resumeOthers = () => {
|
const resumeOthers = () => {
|
||||||
const swipeHandler = (Bangle as {swipeHandler?: () => void}).swipeHandler;
|
for(const event in touchEvents){
|
||||||
if(swipeHandler)
|
const handlers = touchEvents[event];
|
||||||
Bangle.on("swipe", swipeHandler);
|
touchEvents[event] = null;
|
||||||
|
|
||||||
|
if(handlers)
|
||||||
|
for(const handler of handlers)
|
||||||
|
Bangle.on(event as any, handler);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue