• Right, I can see why we want to avoid changing Bangle.setUI.

    But as far as I can tell on Bangle.js 1:

        Bangle.setUI({mode:"clock",back:function() {
          Bangle.showClock();
        }});
    

    opens the launcher (instead of the clock) when you press the middle button.

    And

        Bangle.setUI({mode:"custom",back:function() {
          Bangle.showClock();
        }});
    

    does nothing for button presses.

    So we end up needing something like this:

        Bangle.setUI({mode:"custom",
            back: function() { 
                // Bangle.js 2 also calls this for button presses
                Bangle.showClock();
            },
            btn: global.BTN2 ? function(b) { 
                if (b==2) Bangle.showClock(); // only needed for Bangle.js 1
            } : undefined
        });
    

    Bangle.js 2 setUI checks if there are any button listeners, and assigns the back function otherwise, Bangle.js 1 doesn't :-(

    Maybe we could add similar code to the Bangle.js 1 setUI:

        Bangle.on("touch", touchHandler);
        if (Bangle.btnWatches===undefined) // only add back button handler if there are no existing watches
    	    btnWatch = setWatch(function() {
    	      btnWatch = undefined;
    	      options.back();
    	    }, BTN2, {edge:"falling"});
        ...
        // and in widget.remove:
        if (btnWatch) clearWatch(btnWatch);
    

    But I suppose that would lead to the same problem of it not working in older firmware... (On the other hand: it doesn't work now either, so apps that already assign their own BTN2 listeners should be fine?)

About

Avatar for rigrig @rigrig started