Skip to content

Commit 52fa033

Browse files
author
thyttan
committed
Merge branch 'msgtwistscroll' into app-loader
2 parents bd62e91 + 7608697 commit 52fa033

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

apps/msgtwscr/boot.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@
44
onTwistEmitDrag();
55
}
66

7-
// If Fastload Utils is installed this is used:
8-
Bangle.on("message", (_, msg)=>{if (Bangle.CLOCK && msg.new) {
7+
let attachAfterTimeout = ()=>{
98
setTimeout(()=>{
109
if (global.__FILE__=="messagegui.new.js") {
1110
onTwistEmitDrag();
1211
}
13-
},1000)
12+
},700)
1413
// It feels like there's a more elegant solution than checking the filename
15-
// after 1000 milliseconds. But this at least seems to work w/o sometimes
14+
// after 700 milliseconds. But this at least seems to work w/o sometimes
1615
// activating when it shouldn't.
1716
// Maybe we could add events for when fast load and/or Bangle.uiRemove occurs?
1817
// Then that could be used similarly to boot code and/or the `kill` event.
18+
}
19+
20+
// If Fastload Utils is installed this is used:
21+
Bangle.on("message", (_, msg)=>{if (Bangle.CLOCK && msg.new) {
22+
attachAfterTimeout();
1923
}});
2024

2125
// twistThreshold How much acceleration to register a twist of the watch strap? Can be negative for opposite direction. default = 800
2226
// twistMaxY Maximum acceleration in Y to trigger a twist (low Y means watch is facing the right way up). default = -800
2327
// twistTimeout How little time (in ms) must a twist take from low->high acceleration? default = 1000
2428
function onTwistEmitDrag() {
2529
Bangle.setOptions({twistThreshold:2500, twistMaxY:-800, twistTimeout:400});
30+
let isTwistDragging = false;
2631
let twistHandler = ()=>{
27-
Bangle.setLocked(false);
28-
Bangle.setLCDPower(true);
29-
Bangle.emit("swipe",0,-1);
30-
let i = 25;
31-
const int = setInterval(() => {
32-
Bangle.emit("drag", {dy:-3})
33-
i--;
34-
if (i<1) clearInterval(int);
35-
}, 10);
32+
if (!isTwistDragging) {
33+
isTwistDragging = true;
34+
Bangle.setLocked(false);
35+
Bangle.setLCDPower(true);
36+
let i = 25;
37+
const int = setInterval(() => {
38+
Bangle.emit("drag", {dy:-3, b:i===0?0:1})
39+
i--;
40+
if (i<0) {
41+
clearInterval(int);
42+
isTwistDragging = false;
43+
}
44+
}, 10);
45+
}
3646
}
3747
Bangle.on("twist", twistHandler);
3848
// Give messagegui some extra time to add its remove function to
@@ -43,10 +53,10 @@
4353
Bangle.uiRemove = function () {
4454
Bangle.removeListener("twist", twistHandler)
4555
showMessageUIRemove();
56+
// Reset twist drag logic if we go to next message.
57+
attachAfterTimeout();
4658
}
4759
}},
48-
500
49-
)
50-
60+
800)
5161
}
5262
}

0 commit comments

Comments
 (0)