@@ -594,24 +594,32 @@ function sepiaFW_build_ui(){
594594 }
595595
596596 //Update myView
597- var myViewUpdateInterval = 20 * 60 * 1000 ; //<- automatic updates will not be done more than once within this interval
597+ var myViewUpdateInterval = 15 * 60 * 1000 ; //<- automatic updates will not be done more than once within this interval
598598 var lastMyViewUpdate = 0 ;
599+ var myViewPostponedUpdateTries = 0 ;
599600 var myViewUpdateTimer ;
600601 var contextEventsLoadDelayTimer = undefined ;
602+ var timeEventsLoadDelayTimer = undefined ;
601603 UI . updateMyView = function ( forceUpdate , checkGeolocationFirst , updateSource ) {
602604 //console.log('My-view update source: ' + updateSource); //DEBUG
603605
604606 //is client active or demo-mode?
605607 if ( ( ! SepiaFW . client . isActive ( ) || ! SepiaFW . assistant . id ) && ! SepiaFW . client . isDemoMode ( ) ) {
606608 clearTimeout ( myViewUpdateTimer ) ;
609+ myViewPostponedUpdateTries ++ ;
607610 myViewUpdateTimer = setTimeout ( function ( ) {
608611 //try again
609- UI . updateMyView ( true , checkGeolocationFirst , 'notActiveRetry' ) ;
610- } , 10000 ) ;
611- SepiaFW . debug . err ( "Events: tried to update my-view before client is active! Will try again in 10s." ) ;
612+ if ( myViewPostponedUpdateTries <= 3 ) {
613+ UI . updateMyView ( true , checkGeolocationFirst , 'notActiveRetry' ) ;
614+ } else {
615+ myViewPostponedUpdateTries = 0 ;
616+ }
617+ } , 8000 ) ;
618+ SepiaFW . debug . err ( "Events: tried to update my-view before client is active! Will try again in 8s." ) ;
612619 return ;
613620 }
614621 //console.log('passed');
622+ myViewPostponedUpdateTries = 0 ;
615623
616624 //with GPS first
617625 if ( checkGeolocationFirst ) {
@@ -621,10 +629,10 @@ function sepiaFW_build_ui(){
621629 //console.log('---------------GET BEST LOCATION--------------'); //DEBUG
622630 SepiaFW . geocoder . getBestLocation ( ) ;
623631 } else {
624- UI . updateMyView ( false , false , 'geoCoderBlockedUpdate' ) ; //TODO: should we use 'forceUpdate' variable instead of false?
632+ UI . updateMyView ( forceUpdate , false , 'geoCoderBlockedUpdate' ) ; //TODO: should we use 'forceUpdate' variable instead of false?
625633 }
626634 } else {
627- UI . updateMyView ( false , false , 'geoCoderSkippedUpdate' ) ; //TODO: should we use 'forceUpdate' variable instead of false?
635+ UI . updateMyView ( forceUpdate , false , 'geoCoderSkippedUpdate' ) ; //TODO: should we use 'forceUpdate' variable instead of false?
628636 }
629637
630638 //without GPS
@@ -641,8 +649,8 @@ function sepiaFW_build_ui(){
641649 //contextual events update
642650 UI . updateMyContextualEvents ( forceUpdate ) ;
643651
644- //check for near timeEvents (within 18h (before) and 120h (past))
645- UI . updateMyTimers ( now + 18 * 60 * 60 * 1000 ) ;
652+ //reload timers and check for near timeEvents
653+ UI . updateMyTimeEvents ( forceUpdate ) ;
646654
647655 //trigger my custom buttons refresh (checks internally if buttons have changed)
648656 if ( SepiaFW . ui . customButtons ) {
@@ -651,12 +659,13 @@ function sepiaFW_build_ui(){
651659 }
652660 }
653661 }
662+ //Update the timers shown on my-view (no database reload)
654663 UI . updateMyTimers = function ( maximumPreviewTargetTime ) {
655- var maxTargetTime = maximumPreviewTargetTime || ( new Date ( ) . getTime ( ) + 18 * 60 * 60 * 1000 ) ;
664+ var maxTargetTime = maximumPreviewTargetTime || ( new Date ( ) . getTime ( ) + 18 * 60 * 60 * 1000 ) ; //within 18h (before) and 120h (past)
656665 var includePastMs = 120 * 60 * 60 * 1000 ;
657666 var nextTimers = SepiaFW . events . getNextTimeEvents ( maxTargetTime , '' , includePastMs ) ;
658667 var myView = document . getElementById ( 'sepiaFW-my-view' ) ; //TODO: don't we have a method for this or a permanent variable?
659- //TODO: clean-up my-view of old timers first
668+ //TODO: smart clean-up of old timers - This has to be done before when we get the new list
660669 $ . each ( nextTimers , function ( index , Timer ) {
661670 //check if alarm is present in myView
662671 var timerPresentInMyView = $ ( myView ) . find ( '[data-id="' + Timer . data . eventId + '"]' ) ; //TODO: we don't need this if we clean first
@@ -669,6 +678,15 @@ function sepiaFW_build_ui(){
669678 }
670679 } ) ;
671680 }
681+
682+ //Reload from database and show events
683+ UI . updateMyTimeEvents = function ( forceUpdate ) {
684+ if ( timeEventsLoadDelayTimer ) clearTimeout ( timeEventsLoadDelayTimer ) ;
685+ timeEventsLoadDelayTimer = setTimeout ( function ( ) {
686+ //console.log('---------------GET TIME EVENTS--------------'); //DEBUG
687+ SepiaFW . events . setupTimeEvents ( forceUpdate ) ; //just in case we want to use GPS some day (see below)
688+ } , 1000 ) ;
689+ }
672690 UI . updateMyContextualEvents = function ( forceUpdate ) {
673691 if ( contextEventsLoadDelayTimer ) clearTimeout ( contextEventsLoadDelayTimer ) ;
674692 contextEventsLoadDelayTimer = setTimeout ( function ( ) {
@@ -742,13 +760,13 @@ function sepiaFW_build_ui(){
742760 SepiaFW . debug . info ( 'UI.listenToVisibilityChange: ' + document [ visibility ] ) ;
743761
744762 //became visible
745- if ( SepiaFW . client . isActive ( ) ) {
763+ // if (SepiaFW.client.isActive()){
746764 if ( ! isFirstVisibilityChange && ( UI . isVisible ( ) || forceTriggerVisible ) ) {
747765 //update myView (is automatically skipped if called too early)
748766 UI . updateMyView ( false , true , 'visibilityChange' ) ;
749767 }
750768 isFirstVisibilityChange = false ;
751- }
769+ // }
752770 }
753771 //broadcaster for myView show
754772 var isFirstMyViewShow = true ;
@@ -772,6 +790,8 @@ function sepiaFW_build_ui(){
772790 if ( ! SepiaFW . client . allowBackgroundConnection ) {
773791 //reconnect
774792 SepiaFW . client . resumeClient ( ) ;
793+ //GPS
794+
775795 }
776796 } , 100 ) ;
777797 }
0 commit comments