From ed46a278ee5faa513841626506d7675621da36a0 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Mon, 26 May 2025 22:56:07 +0200 Subject: [PATCH 1/2] Bangle_setUI_Q3: fix btn back handler was not always rm:ed correctly --- libs/js/banglejs/Bangle_setUI_Q3.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index 29a8e7645..aad848278 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -10,10 +10,11 @@ hadBackWidget = true; // if we had a back widget already, don't redraw at the end WIDGETS.back.remove(options.back); // only redraw when removing if we don't have options.back } - if (Bangle.btnWatches) { + let clearBtnWatches = function() { Bangle.btnWatches.forEach(clearWatch); delete Bangle.btnWatches; } + if (Bangle.btnWatches) clearBtnWatches(); if (Bangle.swipeHandler) { Bangle.removeListener("swipe", Bangle.swipeHandler); delete Bangle.swipeHandler; @@ -118,13 +119,15 @@ if (options.redraw) // handler for redrawing the UI Bangle.uiRedraw = options.redraw; if (options.back) { - var btnWatch; + let isBtnBackFunc = false; // only add back button handler if there's no existing watch on BTN1 - if (Bangle.btnWatches===undefined) - btnWatch = setWatch(function() { - btnWatch = undefined; + if (Bangle.btnWatches===undefined) { + Bangle.btnWatches = [ setWatch(function() { + Bangle.btnWatches = undefined; options.back(); - }, BTN1, {edge:"rising"}); + }, BTN1, {edge:"rising"}) ]; + isBtnBackFunc = true; + } // if we have widgets loaded *and* visible at the top, add a back widget (see #3788) if (global.WIDGETS && Bangle.appRect.y) { // add our own touch handler for touching in the top left @@ -143,7 +146,7 @@ remove:function(noclear){ var w = WIDGETS.back; if (w.area!="tl") noclear=true; // area="" is set by widget_utils.hide, so avoid drawing - if (btnWatch) clearWatch(btnWatch); + if (isBtnBackFunc && Bangle.btnWatches) clearBtnWatches(); Bangle.removeListener("touch", touchHandler); if (!noclear) g.reset().clearRect({x:w.x, y:w.y, w:24,h:24}); delete WIDGETS.back; From ba74d7eff35570af8d58498fed3237f23f4c37a8 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 5 Jun 2025 16:41:44 +0100 Subject: [PATCH 2/2] remove isBtnBackFunc logic as not needed --- libs/js/banglejs/Bangle_setUI_Q3.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index aad848278..a73e9fbb2 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -10,11 +10,10 @@ hadBackWidget = true; // if we had a back widget already, don't redraw at the end WIDGETS.back.remove(options.back); // only redraw when removing if we don't have options.back } - let clearBtnWatches = function() { + if (Bangle.btnWatches) { Bangle.btnWatches.forEach(clearWatch); delete Bangle.btnWatches; } - if (Bangle.btnWatches) clearBtnWatches(); if (Bangle.swipeHandler) { Bangle.removeListener("swipe", Bangle.swipeHandler); delete Bangle.swipeHandler; @@ -119,14 +118,12 @@ if (options.redraw) // handler for redrawing the UI Bangle.uiRedraw = options.redraw; if (options.back) { - let isBtnBackFunc = false; // only add back button handler if there's no existing watch on BTN1 if (Bangle.btnWatches===undefined) { Bangle.btnWatches = [ setWatch(function() { - Bangle.btnWatches = undefined; + Bangle.btnWatches = undefined; // watch doesn't repeat options.back(); }, BTN1, {edge:"rising"}) ]; - isBtnBackFunc = true; } // if we have widgets loaded *and* visible at the top, add a back widget (see #3788) if (global.WIDGETS && Bangle.appRect.y) { @@ -146,7 +143,6 @@ remove:function(noclear){ var w = WIDGETS.back; if (w.area!="tl") noclear=true; // area="" is set by widget_utils.hide, so avoid drawing - if (isBtnBackFunc && Bangle.btnWatches) clearBtnWatches(); Bangle.removeListener("touch", touchHandler); if (!noclear) g.reset().clearRect({x:w.x, y:w.y, w:24,h:24}); delete WIDGETS.back;