|
1 | 1 | (function(mode, cb) {
|
2 |
| - var options = {}; |
| 2 | + var options = {}, |
| 3 | + hadBackWidget = false, |
| 4 | + b = ()=>Bangle.buzz(30); |
3 | 5 | if ("object"==typeof mode) {
|
4 | 6 | options = mode;
|
5 | 7 | mode = options.mode;
|
6 | 8 | if (!mode) throw new Error("Missing mode in setUI({...})");
|
7 | 9 | }
|
8 |
| - var hadBackWidget = false; |
9 | 10 | if (global.WIDGETS && WIDGETS.back) {
|
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
|
|
39 | 40 | }
|
40 | 41 | g.reset();// reset graphics state, just in case
|
41 | 42 | if (!mode) return;
|
42 |
| - function b() { |
43 |
| - try{Bangle.buzz(30);}catch(e){} |
44 |
| - } |
| 43 | + |
45 | 44 | if (mode=="updown") {
|
46 | 45 | if (options.drag) throw new Error("Custom drag handler not supported in mode updown!")
|
47 | 46 | var dy = 0;
|
|
103 | 102 | throw new Error("Unknown UI mode "+E.toJS(mode));
|
104 | 103 | if (options.clock) Bangle.CLOCK=1;
|
105 | 104 | if (options.touch) {
|
106 |
| - if (Bangle.touchHandler) { // don't overwrite existing touch handler if using updown/etc (#2648) |
107 |
| - Bangle.touchHandler2 = options.touch; |
108 |
| - Bangle.on("touch", Bangle.touchHandler2); |
109 |
| - } else { |
110 |
| - Bangle.touchHandler = options.touch; |
111 |
| - Bangle.on("touch", Bangle.touchHandler); |
112 |
| - } |
| 105 | + if (Bangle.touchHandler) // don't overwrite existing touch handler if using updown/etc (#2648) |
| 106 | + Bangle.on("touch", Bangle.touchHandler2 = options.touch); |
| 107 | + else |
| 108 | + Bangle.on("touch", Bangle.touchHandler = options.touch); |
113 | 109 | }
|
114 | 110 | if (options.drag) {
|
115 | 111 | Bangle.dragHandler = options.drag;
|
|
131 | 127 | if (Bangle.btnWatches===undefined)
|
132 | 128 | Bangle.btnWatches = [ setWatch(function() {
|
133 | 129 | Bangle.btnWatches = undefined; // watch doesn't repeat
|
134 |
| - options.back(); |
| 130 | + b().then(() => options.back()); |
135 | 131 | }, BTN1, {edge:"rising"}) ];
|
136 | 132 | // if we have widgets loaded *and* visible at the top, add a back widget (see #3788)
|
137 | 133 | if (global.WIDGETS && Bangle.appRect.y) {
|
|
140 | 136 | if (e.y<36 && e.x<48) {
|
141 | 137 | e.handled = true;
|
142 | 138 | E.stopEventPropagation(); // stop subsequent touch handlers from being called
|
143 |
| - options.back(); |
| 139 | + b().then(() => options.back()); |
144 | 140 | }
|
145 | 141 | };
|
146 | 142 | Bangle.prependListener("touch", touchHandler);
|
|
0 commit comments