Skip to content

Commit

Permalink
Respect resume - if paused wait until resume before triggering start …
Browse files Browse the repository at this point in the history
…up events
  • Loading branch information
Morten Henriksen committed Jan 27, 2015
1 parent 78b679e commit 77d3bce
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/client/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var coldstart = true;
var startupTime = new Date();
var startupThreshold = 1000; // ms
var paused = false;
var waitingMessage = null;

var _atStartup = function() {
// If we were triggered before resume then its a startup
Expand Down Expand Up @@ -89,8 +90,12 @@ onNotificationAPN = function(e) {
// E.ejson should be a string - we send it directly to payload
if (e.ejson) unifiedMessage.payload = _parsePayload(e.ejson);

// Trigger notification
onNotification(unifiedMessage);
if (paused) {
waitingMessage = unifiedMessage;
} else {
// Trigger notification
onNotification(unifiedMessage);
}
};

// handle GCM notifications for Android and Fire OS
Expand Down Expand Up @@ -130,8 +135,12 @@ onNotificationGCM = function(e) {
// parsePayload will do the convertion for us
if (e.payload.ejson) unifiedMessage.payload = _parsePayload(e.payload.ejson);

// Trigger notification
onNotification(unifiedMessage);
if (paused) {
waitingMessage = unifiedMessage;
} else {
// Trigger notification
onNotification(unifiedMessage);
}
break;

case 'error':
Expand Down Expand Up @@ -232,6 +241,14 @@ Push.Configure = function(options) {
paused = false;
// Reset startup time at resume
startupTime = new Date();

if (waitingMessage) {
// Trigger notification
onNotification(waitingMessage);

// Reset waiting message
waitingMessage = null;
}
});

var pushNotification = window.plugins.pushNotification;
Expand Down

0 comments on commit 77d3bce

Please # to comment.