Skip to content

Commit 85fac9d

Browse files
author
thyttan
committed
messagegui: refactoring more
1 parent 4f2bae0 commit 85fac9d

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

apps/messagegui/app.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ function showMessagesScroller(msg, persist, alreadyProcessed) {
364364
function reinitAdding(idx) {
365365
setTimeout(() => {
366366
E.showScroller();
367-
if (BTN_WATCH) {clearWatch(BTN_WATCH);}
367+
if (BTN_EXT_SELECT) {clearWatch(BTN_EXT_SELECT);}
368368
showMessagesScroller(MESSAGES[idx],
369369
true, alreadyProcessed);
370370
}, 40);
@@ -388,30 +388,26 @@ function showMessagesScroller(msg, persist, alreadyProcessed) {
388388
prevScrollIdxs[0] = scrollIdx;
389389
},
390390
select : function(scrollIdx, touch) {
391+
WU.show();
391392
const MSG_SELECT = identifyDisplayedMsg(scrollIdx);
392-
if (touch.type == 0) {
393-
WU.show();
394-
if (BTN_WATCH) {clearWatch(BTN_WATCH);}
395-
showMessage(MSG_SELECT.id, true);
396-
}
397-
if (touch.type == 2) {
398-
WU.show();
399-
if (BTN_WATCH) {clearWatch(BTN_WATCH);}
400-
showMessageSettings(MSG_SELECT);
401-
}
393+
if (BTN_EXT_SELECT) {clearWatch(BTN_EXT_SELECT);}
394+
if (!touch) {showMessage(MSG_SELECT.id,true); return}
395+
if (touch.type == 0) {showMessage(MSG_SELECT.id,true);}
396+
if (touch.type == 2) {showMessageSettings(MSG_SELECT);}
402397
}
403398
});
404399

405-
const BTN_WATCH = setWatch(()=>{
400+
// If Bangle.js 2 add an external select hw button handler.
401+
const BTN_EXT_SELECT = ((2===process.env.HWVERSION) && (setWatch(()=>{
406402
Bangle.emit("drag", {dy:0}); // Compatibility with `kineticscroll`, stopping the scroller so it doesn't continue scrolling when the `showMessage` screen is loaded.
407403
// Zero ms timeout as to not move on before the scroller has registered the emitted drag event.
408404
setTimeout(()=>{
409405
const SCROLL_IDX_CENTER_SCREEN = prevScrollIdxs[0]>prevScrollIdxs[1] ?
410-
prevScrollIdxs[0]-LINES_PER_SCREEN/2:prevScrollIdxs[0]+LINES_PER_SCREEN/2;
406+
prevScrollIdxs[0]-LINES_PER_SCREEN/2:prevScrollIdxs[0]+LINES_PER_SCREEN/2;
411407
WU.show();
412408
showMessage(identifyDisplayedMsg(SCROLL_IDX_CENTER_SCREEN).id, true);
413409
},0)
414-
}, BTN, {edge:'rising'});
410+
}, BTN, {edge:'rising'})));
415411
}
416412

417413
function showMessageSettings(msg) {

0 commit comments

Comments
 (0)