1- var SunCalc = require ( "suncalc" ) ; // from modules folder
1+ {
2+ const SunCalc = require ( "suncalc" ) ; // from modules folder
23const storage = require ( 'Storage' ) ;
34const widget_utils = require ( 'widget_utils' ) ;
45const global_settings = storage . readJSON ( "setting.json" , true ) || { } ;
@@ -42,32 +43,32 @@ const maxLines = Math.floor(usableHeight / lineHeight);
4243var numWidth = 0 ;
4344
4445// requires the myLocation app
45- function loadLocation ( ) {
46+ let loadLocation = function ( ) {
4647 location = require ( "Storage" ) . readJSON ( LOCATION_FILE , 1 ) || { } ;
4748 location . lat = location . lat || 0 ;
4849 location . lon = location . lon || 0 ;
4950 location . location = location . location || null ;
50- }
51+ } ;
5152
52- function getHr ( h ) {
53+ let getHr = function ( h ) {
5354 var amPm = "" ;
5455 if ( settings . hr_12 ) {
5556 amPm = h < 12 ? "AM" : "PM" ;
5657 h = h % 12 ;
5758 if ( h == 0 ) h = 12 ;
5859 }
5960 return [ h , amPm ] ;
60- }
61+ } ;
6162
62- function extractTime ( d ) {
63+ let extractTime = function ( d ) {
6364 const out = getHr ( d . getHours ( ) ) ;
6465 const h = out [ 0 ] ;
6566 const amPm = out [ 1 ] ;
6667 const m = d . getMinutes ( ) ;
6768 return `${ h } :${ ( "0" + m ) . substr ( - 2 ) } ${ amPm } ` ;
68- }
69+ } ;
6970
70- function extractDate ( d ) {
71+ let extractDate = function ( d ) {
7172 const weekdays = [ "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" ] ;
7273 const months = [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" ,
7374 "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"
@@ -78,9 +79,9 @@ function extractDate(d) {
7879 const day = d . getDate ( ) ;
7980
8081 return `${ weekday } ${ month } ${ day } ` ;
81- }
82+ } ;
8283
83- function getSteps ( ) {
84+ let getSteps = function ( ) {
8485 try {
8586 return Bangle . getHealthStatus ( "day" ) . steps ;
8687 } catch ( e ) {
@@ -89,9 +90,9 @@ function getSteps() {
8990 else
9091 return null ;
9192 }
92- }
93+ } ;
9394
94- function getVal ( now , loc ) {
95+ let getVal = function ( now , loc ) {
9596 const vals = { } ;
9697 const currentDateStr = extractDate ( now ) ;
9798 if ( loc . location ) {
@@ -107,10 +108,9 @@ function getVal(now, loc) {
107108 vals . batt_pct = E . getBattery ( ) ;
108109 vals . steps = getSteps ( ) ;
109110 return vals ;
110- }
111-
111+ } ;
112112
113- function loadJson ( ) {
113+ let loadJson = function ( ) {
114114 const now = new Date ( ) ;
115115 vals = getVal ( now , location ) ;
116116 //vals.steps = null; // For testing; uncomment to see the steps not appear
@@ -142,9 +142,9 @@ function loadJson() {
142142
143143 jsonText = JSON . stringify ( raw , null , 2 ) ; // just stringify the object
144144 lines = jsonText . split ( "\n" ) ;
145- }
145+ } ;
146146
147- function draw ( ) {
147+ let draw = function ( ) {
148148 g . clear ( ) ;
149149 g . setFontAlign ( - 1 , - 1 ) ;
150150 g . setFont ( "Vector" , 10 ) ;
@@ -169,9 +169,9 @@ function draw() {
169169 }
170170
171171 redraw ( ) ;
172- }
172+ } ;
173173
174- function redraw ( ) {
174+ let redraw = function ( ) {
175175 for ( let i = 0 ; i < maxLines ; i ++ ) {
176176 const lineIndex = i ;
177177 const line = lines [ lineIndex ] ;
@@ -217,19 +217,18 @@ function redraw() {
217217 g . drawString ( line , numWidth , y ) ;
218218 }
219219 }
220- Bangle . drawWidgets ( ) ;
221- }
220+ } ;
222221
223- function clearVals ( ) {
222+ let clearVals = function ( ) {
224223 g . setFont ( "Vector" , fontSize ) ;
225224 g . setFontAlign ( - 1 , - 1 ) ;
226225 valuePositions . forEach ( pos => {
227226 g . setColor ( clrs . bg ) ;
228227 g . fillRect ( pos . x , pos . y , w , pos . y + lineHeight ) ;
229228 } ) ;
230- }
229+ } ;
231230
232- function redrawValues ( ) {
231+ let redrawValues = function ( ) {
233232 loadJson ( ) ;
234233 clearVals ( ) ;
235234 redraw ( ) ;
@@ -238,12 +237,12 @@ function redrawValues() {
238237 drawTimeout = undefined ;
239238 redrawValues ( ) ;
240239 } , 60000 - ( Date . now ( ) % 60000 ) ) ;
241- }
240+ } ;
242241
243242Bangle . on ( 'touch' , ( zone , e ) => {
244243 if ( e . x >= ( buttonY - buttonHeight ) && e . x <= ( buttonX + buttonHeight ) &&
245244 ( e . y >= ( buttonY - buttonHeight ) && e . y <= ( buttonY + buttonHeight ) ) ) {
246- load ( ) ; // Exit app
245+ Bangle . showLauncher ( ) ; // Exit app
247246 }
248247} ) ;
249248
@@ -253,16 +252,9 @@ Bangle.on('backlight', function(on) {
253252 }
254253} ) ;
255254
256- Bangle . setUI ( {
257- mode : "clock" ,
258- remove : function ( ) {
259- if ( drawTimeout ) clearTimeout ( drawTimeout ) ;
260- drawTimeout = undefined ;
261- }
262- } ) ;
263-
255+ Bangle . setUI ( "clock" ) ;
264256loadLocation ( ) ;
265257Bangle . loadWidgets ( ) ;
266258widget_utils . hide ( ) ;
267259draw ( ) ;
268- setTimeout ( Bangle . drawWidgets , 0 ) ;
260+ }
0 commit comments