Skip to content

Commit 34183dd

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

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libs/js/banglejs/Bangle_setUI_Q3.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Bangle.setUI = // Debugging delete before merge
12
(function(mode, cb) {
23
var options = {};
34
if ("object"==typeof mode) {
@@ -10,10 +11,11 @@
1011
hadBackWidget = true; // if we had a back widget already, don't redraw at the end
1112
WIDGETS.back.remove(options.back); // only redraw when removing if we don't have options.back
1213
}
13-
if (Bangle.btnWatches) {
14+
let clearBtnWatches = function() {
1415
Bangle.btnWatches.forEach(clearWatch);
1516
delete Bangle.btnWatches;
1617
}
18+
if (Bangle.btnWatches) clearBtnWatches();
1719
if (Bangle.swipeHandler) {
1820
Bangle.removeListener("swipe", Bangle.swipeHandler);
1921
delete Bangle.swipeHandler;
@@ -118,13 +120,15 @@
118120
if (options.redraw) // handler for redrawing the UI
119121
Bangle.uiRedraw = options.redraw;
120122
if (options.back) {
121-
var btnWatch;
123+
let isBtnBackFunc = false;
122124
// 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;
125+
if (Bangle.btnWatches===undefined) {
126+
Bangle.btnWatches = [ setWatch(function() {
127+
Bangle.btnWatches = undefined;
126128
options.back();
127-
}, BTN1, {edge:"rising"});
129+
}, BTN1, {edge:"rising"}) ];
130+
isBtnBackFunc = true;
131+
}
128132
// if we have widgets loaded *and* visible at the top, add a back widget (see #3788)
129133
if (global.WIDGETS && Bangle.appRect.y) {
130134
// add our own touch handler for touching in the top left
@@ -143,7 +147,7 @@
143147
remove:function(noclear){
144148
var w = WIDGETS.back;
145149
if (w.area!="tl") noclear=true; // area="" is set by widget_utils.hide, so avoid drawing
146-
if (btnWatch) clearWatch(btnWatch);
150+
if (isBtnBackFunc && Bangle.btnWatches) clearBtnWatches();
147151
Bangle.removeListener("touch", touchHandler);
148152
if (!noclear) g.reset().clearRect({x:w.x, y:w.y, w:24,h:24});
149153
delete WIDGETS.back;

0 commit comments

Comments
 (0)