@@ -15,26 +15,11 @@ let playing = false;
1515let progress ;
1616const weatherParameters = { } ;
1717
18- // auto refresh
19- const AUTO_REFRESH_INTERVAL_MS = 500 ;
20- const AUTO_REFRESH_TIME_MS = 600_000 ; // 10 min.
21- const CHK_AUTO_REFRESH_SELECTOR = '#chkAutoRefresh' ;
22- let AutoRefreshIntervalId = null ;
23- let AutoRefreshCountMs = 0 ;
24-
2518const init = async ( ) => {
2619 // set up resize handler
2720 window . addEventListener ( 'resize' , resize ) ;
2821 resize ( ) ;
2922
30- // auto refresh
31- const autoRefresh = localStorage . getItem ( 'autoRefresh' ) ;
32- if ( ! autoRefresh || autoRefresh === 'true' ) {
33- document . querySelector ( CHK_AUTO_REFRESH_SELECTOR ) . checked = true ;
34- } else {
35- document . querySelector ( CHK_AUTO_REFRESH_SELECTOR ) . checked = false ;
36- }
37- document . querySelector ( CHK_AUTO_REFRESH_SELECTOR ) . addEventListener ( 'change' , autoRefreshChange ) ;
3823 generateCheckboxes ( ) ;
3924} ;
4025
@@ -123,12 +108,6 @@ const updateStatus = (value) => {
123108 if ( isPlaying ( ) && value . id === firstDisplayIndex && value . status === STATUS . loaded ) {
124109 navTo ( msg . command . firstFrame ) ;
125110 }
126-
127- // send loaded messaged to parent
128- if ( countLoadedDisplays ( ) < displays . length ) return ;
129-
130- // everything loaded, set timestamps
131- AssignLastUpdate ( new Date ( ) ) ;
132111} ;
133112
134113// note: a display that is "still waiting"/"retrying" is considered loaded intentionally
@@ -202,8 +181,6 @@ const loadDisplay = (direction) => {
202181 idx = wrap ( curIdx + ( i + 1 ) * direction , totalDisplays ) ;
203182 if ( displays [ idx ] . status === STATUS . loaded && displays [ idx ] . timing . totalScreens > 0 ) break ;
204183 }
205- // if new display index is less than current display a wrap occurred, test for reload timeout
206- if ( idx <= curIdx && refreshCheck ( ) ) return ;
207184 const newDisplay = displays [ idx ] ;
208185 // hide all displays
209186 hideAllCanvases ( ) ;
@@ -320,83 +297,8 @@ const populateWeatherParameters = (params) => {
320297 document . querySelector ( '#spanZoneId' ) . innerHTML = params . zoneId ;
321298} ;
322299
323- const autoRefreshChange = ( e ) => {
324- const { checked } = e . target ;
325-
326- if ( checked ) {
327- startAutoRefreshTimer ( ) ;
328- } else {
329- stopAutoRefreshTimer ( ) ;
330- }
331-
332- localStorage . setItem ( 'autoRefresh' , checked ) ;
333- } ;
334-
335- const AssignLastUpdate = ( date ) => {
336- if ( date ) {
337- document . querySelector ( '#spanLastRefresh' ) . innerHTML = date . toLocaleString ( 'en-US' , {
338- weekday : 'short' , month : 'short' , day : 'numeric' , year : 'numeric' , hour : 'numeric' , minute : 'numeric' , second : 'numeric' , timeZoneName : 'short' ,
339- } ) ;
340- if ( document . querySelector ( CHK_AUTO_REFRESH_SELECTOR ) . checked ) startAutoRefreshTimer ( ) ;
341- } else {
342- document . querySelector ( '#spanLastRefresh' ) . innerHTML = '(none)' ;
343- }
344- } ;
345-
346300const latLonReceived = ( data , haveDataCallback ) => {
347301 getWeather ( data , haveDataCallback ) ;
348- AssignLastUpdate ( null ) ;
349- } ;
350-
351- const startAutoRefreshTimer = ( ) => {
352- // Ensure that any previous timer has already stopped.
353- // check if timer is running
354- if ( AutoRefreshIntervalId ) return ;
355-
356- // Reset the time elapsed.
357- AutoRefreshCountMs = 0 ;
358-
359- const AutoRefreshTimer = ( ) => {
360- // Increment the total time elapsed.
361- AutoRefreshCountMs += AUTO_REFRESH_INTERVAL_MS ;
362-
363- // Display the count down.
364- let RemainingMs = ( AUTO_REFRESH_TIME_MS - AutoRefreshCountMs ) ;
365- if ( RemainingMs < 0 ) {
366- RemainingMs = 0 ;
367- }
368- const dt = new Date ( RemainingMs ) ;
369- document . querySelector ( '#spanRefreshCountDown' ) . innerHTML = `${ dt . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ dt . getSeconds ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
370-
371- // Time has elapsed.
372- if ( AutoRefreshCountMs >= AUTO_REFRESH_TIME_MS && ! isPlaying ( ) ) loadTwcData ( ) ;
373- } ;
374- AutoRefreshIntervalId = window . setInterval ( AutoRefreshTimer , AUTO_REFRESH_INTERVAL_MS ) ;
375- AutoRefreshTimer ( ) ;
376- } ;
377- const stopAutoRefreshTimer = ( ) => {
378- if ( AutoRefreshIntervalId ) {
379- window . clearInterval ( AutoRefreshIntervalId ) ;
380- document . querySelector ( '#spanRefreshCountDown' ) . innerHTML = '--:--' ;
381- AutoRefreshIntervalId = null ;
382- }
383- } ;
384-
385- const refreshCheck = ( ) => {
386- // Time has elapsed.
387- if ( AutoRefreshCountMs >= AUTO_REFRESH_TIME_MS && isPlaying ( ) ) {
388- loadTwcData ( ) ;
389- return true ;
390- }
391- return false ;
392- } ;
393-
394- const loadTwcData = ( ) => {
395- if ( loadTwcData . callback ) loadTwcData . callback ( ) ;
396- } ;
397-
398- const registerRefreshData = ( callback ) => {
399- loadTwcData . callback = callback ;
400302} ;
401303
402304const timeZone = ( ) => weatherParameters . timeZone ;
@@ -414,7 +316,5 @@ export {
414316 msg ,
415317 message ,
416318 latLonReceived ,
417- stopAutoRefreshTimer ,
418- registerRefreshData ,
419319 timeZone ,
420320} ;
0 commit comments