Skip to content

Commit

Permalink
when sleeping, nullng last track items.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed Mar 6, 2016
1 parent f6916ee commit c24bff2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/background.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ var createOrUpdate = function (appTrackItem) {
console.log('midnight');
var almostMidnight = moment(appTrackItem.beginDate).startOf('day').add(1, 'days').subtract(1, 'seconds').toDate();
var afterMidnight = dateToAfterMidnight(appTrackItem.beginDate);
var originalEndDate = appTrackItem.endDate;

logger.log('Midnight- almostMidnight: ' + almostMidnight + ', ' + afterMidnight);
appTrackItem.endDate = almostMidnight;
createOrUpdate(appTrackItem).then(function (item1) {
lastAppTrackItemSaved = null;
logger.log('Midnight- Saved one: ' + item1);
item1.beginDate = afterMidnight;
item1.endDate = originalEndDate;
createOrUpdate(item1).then(function (item2) {
logger.log('Midnight- Saved second: ' + item2);
deferred.resolve(item2);
Expand Down Expand Up @@ -186,7 +188,7 @@ var createOrUpdate = function (appTrackItem) {
}


return deferred.promise;
return deferred;
}

var addRawTrackItemToList = function (item) {
Expand Down Expand Up @@ -301,6 +303,8 @@ var saveIdleTrackItem = function (seconds) {

BackgroundService.onSleep = function () {
isSleeping = true;
lastStatusTrackItemSaved = null;
lastAppTrackItemSaved = null;
};

BackgroundService.onResume = function () {
Expand Down

0 comments on commit c24bff2

Please sign in to comment.