Skip to content

Commit 1b88dd2

Browse files
author
thyttan
committed
msgtwscr: tweak to work with recent messagegui updates
1 parent c519190 commit 1b88dd2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

apps/msgtwscr/boot.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,43 @@
1010
if (global.__FILE__=="messagegui.new.js") {
1111
onTwistEmitDrag();
1212
}
13-
},700) // It feels like there's a more elegant solution than checking the filename after 700 milliseconds. But this at least seems to work w/o sometimes activating when it shouldn't.
13+
},1000)
14+
// 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
16+
// activating when it shouldn't.
17+
// Maybe we could add events for when fast load and/or Bangle.uiRemove occurs?
18+
// Then that could be used similarly to boot code and/or the `kill` event.
1419
}});
1520

1621
// twistThreshold How much acceleration to register a twist of the watch strap? Can be negative for opposite direction. default = 800
1722
// twistMaxY Maximum acceleration in Y to trigger a twist (low Y means watch is facing the right way up). default = -800
1823
// twistTimeout How little time (in ms) must a twist take from low->high acceleration? default = 1000
1924
function onTwistEmitDrag() {
2025
Bangle.setOptions({twistThreshold:2500, twistMaxY:-800, twistTimeout:400});
21-
Bangle.on("twist", ()=>{
26+
let twistHandler = ()=>{
2227
Bangle.setLocked(false);
2328
Bangle.setLCDPower(true);
29+
Bangle.emit("swipe",0,-1);
2430
let i = 25;
2531
const int = setInterval(() => {
2632
Bangle.emit("drag", {dy:-3})
2733
i--;
2834
if (i<1) clearInterval(int);
2935
}, 10);
30-
});
36+
}
37+
Bangle.on("twist", twistHandler);
38+
// Give messagegui some extra time to add its remove function to
39+
// Bangle.uiRemove, then attach msgtwscr remove logic.
40+
setTimeout(
41+
()=>{if (Bangle.uiRemove) {
42+
let showMessageUIRemove = Bangle.uiRemove;
43+
Bangle.uiRemove = function () {
44+
Bangle.removeListener("twist", twistHandler)
45+
showMessageUIRemove();
46+
}
47+
}},
48+
500
49+
)
3150

3251
}
3352
}

0 commit comments

Comments
 (0)