Skip to content

Commit 7608697

Browse files
author
thyttan
committed
msgtwscr: adapt to the recent messagegui updates
1 parent 79e7f63 commit 7608697

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

apps/msgtwscr/boot.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
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();
@@ -16,23 +15,34 @@
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,6 +53,8 @@
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
}},
4860
800)

0 commit comments

Comments
 (0)