EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep
264 stars 106 forks source link

Not working after long time periods #43

Open fquirogam opened 6 years ago

fquirogam commented 6 years ago

I used this plugin in an Android tablet that should awake at 8:00 am and sleep at 8:00 pm every day, in a survey app in a local business,everything works right the first 24/48 hours but after that time, the app never makes the tablet awake and keeps the screen locked all time.

The code is inside a setInterval that every minute runs a function that checks the current time and keeps the tablet awaken or lets the tablet sleep.

EddyVerbruggen commented 6 years ago

Without a project that demonstrates this flaw I can’t spend time on this.

fquirogam commented 6 years ago

`$rootScope.compruebaHora=function(){ $scope.date=new Date(); $scope.nowhour=$scope.date.getHours(); $scope.nowminute=$scope.date.getMinutes();

  $rootScope.compruebaActividad();

  if($rootScope.actividad==false){
    $rootScope.screensaver=setTimeout($rootScope.openModal,$rootScope.timeScreenSaver);

    console.log($scope.date.getHours());

    if($scope.nowhour>$scope.inihour && $scope.nowhour<$scope.finhour){
      //awake
      window.plugins.insomnia.keepAwake();
      $scope.despertar();
    } else {
      if(($scope.nowhour==$scope.inihour && $scope.nowminute>=$scope.iniminute) && ($scope.nowhour==$scope.finhour && $scope.nowminute<=$scope.finminute)){
        //awake
        window.plugins.insomnia.keepAwake();
        $scope.despertar();
      } else {
        //sleep
        window.plugins.insomnia.allowSleepAgain();
      }
    }
  } else{
    $scope.stopScreenSaver();
  }`