Skip to content

Commit 553b5b5

Browse files
author
thyttan
committed
swipeinv: (WIP) Add inversion of drag events. Refactor to hijack and modify the
events instead of the handling of them. This should add compatibility with most apps, even if Bangle.setUI is not used.
1 parent a058b08 commit 553b5b5

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

apps/swipeinv/ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
0.01: New app!
22
0.02: Minor code improvements
3+
0.03: (WIP) Add inversion of drag events. Refactor to hijack and modify the
4+
events instead of the handling of them. This should add compatibility with
5+
most apps, even if Bangle.setUI is not used.

apps/swipeinv/boot.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
{
2-
// TODO: Should the global case just hijack the swipe and drag events, modifying them before passing on to other listeners?
3-
// - That could be a new separate bootloader app instead though?
4-
52
const settings = Object.assign({
63
global: false,
74
apps: []
85
}, require("Storage").readJSON("swipeinv.json", true) || {});
96

10-
if (settings.global || settings.apps.length > 0) {
11-
const setURIOrig = Bangle.setUI;
12-
Bangle.setUI = (mode, callback) => {
13-
if (typeof mode === "object" && mode.swipe) {
7+
setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added.
8+
if (settings.global || settings.apps.length > 0) {
9+
10+
let swipeInverter = (dirLR, dirUD, obj) => {
1411
if (settings.global ^ settings.apps.includes(global.__FILE__)) {
15-
const origSwipeCb = mode.swipe;
16-
mode.swipe = (dirLR, dirUD) => origSwipeCb(dirLR * -1, dirUD * -1);
12+
if (!(obj && obj.inverted)) {
13+
E.stopEventPropagation();
14+
obj = Object.assign({inverted:true}, obj);
15+
16+
Bangle.emit("swipe", dirLR * -1, dirUD * -1, obj)
17+
}
1718
}
1819
}
19-
if (typeof mode === "object" && mode.drag) {
20+
21+
let dragInverter = (e) => {
2022
if (settings.global ^ settings.apps.includes(global.__FILE__)) {
21-
const origDragCb = mode.drag;
22-
mode.drag = (e) => {
23+
if (!e.inverted) {
24+
E.stopEventPropagation();
25+
e.inverted = true;
26+
2327
e.dx *= -1;
2428
e.dy *= -1;
25-
origDragCb(e);
29+
Bangle.emit("drag", e);
2630
}
2731
}
2832
}
29-
return setURIOrig(mode, callback);
30-
};
31-
}
33+
34+
Bangle.prependListener("swipe", swipeInverter);
35+
Bangle.prependListener("drag", dragInverter);
36+
37+
}
38+
}, 0)
3239
}

apps/swipeinv/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Swipe inversion",
44
"shortName":"Swipe inv.",
55
"icon": "app.png",
6-
"version": "0.02",
6+
"version": "0.03",
77
"description": "Inverts swipe direction globally or per app, see settings. If global inversion is enabled, you can unselect the inversion per app and vice versa.",
88
"readme":"README.md",
99
"type": "bootloader",

0 commit comments

Comments
 (0)