From c6255ce9c8f761746df72eda06613f7bdc9b23a0 Mon Sep 17 00:00:00 2001 From: Rarder44 Date: Fri, 18 Nov 2022 17:18:59 +0100 Subject: [PATCH] cleanup code and fix fastload issue --- apps/rebble/ChangeLog | 3 +- apps/rebble/metadata.json | 2 +- apps/rebble/rebble.app.js | 94 ++++++++++++++++++++++----------------- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/apps/rebble/ChangeLog b/apps/rebble/ChangeLog index 9e21d1b22..7255b1785 100644 --- a/apps/rebble/ChangeLog +++ b/apps/rebble/ChangeLog @@ -10,4 +10,5 @@ 0.10: Tell clock widgets to hide. 0.11: fix issue https://github.com/espruino/BangleApps/issues/2128 (#2128) ( settings undefined ) 0.12: implemented widget_utils -0.13: convert var/function into let \ No newline at end of file +0.13: convert var/function into let +0.14: cleanup code and fix fastload issue \ No newline at end of file diff --git a/apps/rebble/metadata.json b/apps/rebble/metadata.json index 972cb7e11..9a746a0f9 100644 --- a/apps/rebble/metadata.json +++ b/apps/rebble/metadata.json @@ -2,7 +2,7 @@ "id": "rebble", "name": "Rebble Clock", "shortName": "Rebble", - "version": "0.13", + "version": "0.14", "description": "A Pebble style clock, with configurable background, three sidebars including steps, day, date, sunrise, sunset, long live the rebellion", "readme": "README.md", "icon": "rebble.png", diff --git a/apps/rebble/rebble.app.js b/apps/rebble/rebble.app.js index 6c39b8bc2..ef75bbb21 100644 --- a/apps/rebble/rebble.app.js +++ b/apps/rebble/rebble.app.js @@ -291,48 +291,8 @@ Graphics.prototype.setFontKdamThmor = function(scale) { } - log_debug("starting.."); - loadSettings(); - loadLocation(); - - if(settings.autoCycle || settings.sideTap==0) - { - Bangle.setUI({ - mode : "clockupdown", - remove : function() { - // Called to unload all of the clock app - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = undefined; - delete Graphics.prototype.setFontKdamThmor; - }}, - btn=> { - if (btn<0) prevSidebar(); - if (btn>0) nextSidebar(); - draw(); - }); - - } - else{ - Bangle.setUI({ - mode : "clock", - remove : function() { - // Called to unload all of the clock app - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = undefined; - delete Graphics.prototype.setFontKdamThmor; - }}); - } - - - Bangle.loadWidgets(); - draw(); - require("widget_utils").hide(); - - - - - Bangle.on('charging', function(charging) { + let chargingListener= function(charging) { //redraw the sidebar ( with the battery ) switch(sideBar) { @@ -343,5 +303,55 @@ Graphics.prototype.setFontKdamThmor = function(scale) { drawSideBar2(); break; } - }); + } + + let deleteAll=function() + { + // Called to unload all of the clock app + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontKdamThmor; + Bangle.removeListener('charging',chargingListener); + } + + let main=function(){ + + + log_debug("starting.."); + loadSettings(); + loadLocation(); + + if(settings.autoCycle || settings.sideTap==0) + { + Bangle.setUI({ + mode : "clockupdown", + remove : deleteAll + }, + btn=> { + if (btn<0) prevSidebar(); + if (btn>0) nextSidebar(); + draw(); + }); + + } + else{ + Bangle.setUI({ + mode : "clock", + remove : deleteAll + }); + } + + + + Bangle.on('charging',chargingListener); + + + Bangle.loadWidgets(); + draw(); + require("widget_utils").hide(); + + } + + + main(); } \ No newline at end of file