|
| 1 | +Bangle.setUI = // Debugging delete before merge |
1 | 2 | (function(mode, cb) { |
2 | 3 | var options = {}; |
3 | 4 | if ("object"==typeof mode) { |
|
10 | 11 | hadBackWidget = true; // if we had a back widget already, don't redraw at the end |
11 | 12 | WIDGETS.back.remove(options.back); // only redraw when removing if we don't have options.back |
12 | 13 | } |
13 | | - if (Bangle.btnWatches) { |
| 14 | + let clearBtnWatches = function() { |
14 | 15 | Bangle.btnWatches.forEach(clearWatch); |
15 | 16 | delete Bangle.btnWatches; |
16 | 17 | } |
| 18 | + if (Bangle.btnWatches) clearBtnWatches(); |
17 | 19 | if (Bangle.swipeHandler) { |
18 | 20 | Bangle.removeListener("swipe", Bangle.swipeHandler); |
19 | 21 | delete Bangle.swipeHandler; |
|
118 | 120 | if (options.redraw) // handler for redrawing the UI |
119 | 121 | Bangle.uiRedraw = options.redraw; |
120 | 122 | if (options.back) { |
121 | | - var btnWatch; |
| 123 | + let isBtnBackFunc = false; |
122 | 124 | // 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; |
126 | 128 | options.back(); |
127 | | - }, BTN1, {edge:"rising"}); |
| 129 | + }, BTN1, {edge:"rising"}) ]; |
| 130 | + isBtnBackFunc = true; |
| 131 | + } |
128 | 132 | // if we have widgets loaded *and* visible at the top, add a back widget (see #3788) |
129 | 133 | if (global.WIDGETS && Bangle.appRect.y) { |
130 | 134 | // add our own touch handler for touching in the top left |
|
143 | 147 | remove:function(noclear){ |
144 | 148 | var w = WIDGETS.back; |
145 | 149 | 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(); |
147 | 151 | Bangle.removeListener("touch", touchHandler); |
148 | 152 | if (!noclear) g.reset().clearRect({x:w.x, y:w.y, w:24,h:24}); |
149 | 153 | delete WIDGETS.back; |
|
0 commit comments