Skip to content

Commit ed46a27

Browse files
committed
Bangle_setUI_Q3: fix btn back handler was not always rm:ed correctly
1 parent 02337f4 commit ed46a27

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

libs/js/banglejs/Bangle_setUI_Q3.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
hadBackWidget = true; // if we had a back widget already, don't redraw at the end
1111
WIDGETS.back.remove(options.back); // only redraw when removing if we don't have options.back
1212
}
13-
if (Bangle.btnWatches) {
13+
let clearBtnWatches = function() {
1414
Bangle.btnWatches.forEach(clearWatch);
1515
delete Bangle.btnWatches;
1616
}
17+
if (Bangle.btnWatches) clearBtnWatches();
1718
if (Bangle.swipeHandler) {
1819
Bangle.removeListener("swipe", Bangle.swipeHandler);
1920
delete Bangle.swipeHandler;
@@ -118,13 +119,15 @@
118119
if (options.redraw) // handler for redrawing the UI
119120
Bangle.uiRedraw = options.redraw;
120121
if (options.back) {
121-
var btnWatch;
122+
let isBtnBackFunc = false;
122123
// only add back button handler if there's no existing watch on BTN1
123-
if (Bangle.btnWatches===undefined)
124-
btnWatch = setWatch(function() {
125-
btnWatch = undefined;
124+
if (Bangle.btnWatches===undefined) {
125+
Bangle.btnWatches = [ setWatch(function() {
126+
Bangle.btnWatches = undefined;
126127
options.back();
127-
}, BTN1, {edge:"rising"});
128+
}, BTN1, {edge:"rising"}) ];
129+
isBtnBackFunc = true;
130+
}
128131
// if we have widgets loaded *and* visible at the top, add a back widget (see #3788)
129132
if (global.WIDGETS && Bangle.appRect.y) {
130133
// add our own touch handler for touching in the top left
@@ -143,7 +146,7 @@
143146
remove:function(noclear){
144147
var w = WIDGETS.back;
145148
if (w.area!="tl") noclear=true; // area="" is set by widget_utils.hide, so avoid drawing
146-
if (btnWatch) clearWatch(btnWatch);
149+
if (isBtnBackFunc && Bangle.btnWatches) clearBtnWatches();
147150
Bangle.removeListener("touch", touchHandler);
148151
if (!noclear) g.reset().clearRect({x:w.x, y:w.y, w:24,h:24});
149152
delete WIDGETS.back;

0 commit comments

Comments
 (0)