Skip to content

Commit 77d3bce

Browse files
author
Morten Henriksen
committed
Respect resume - if paused wait until resume before triggering start up events
1 parent 78b679e commit 77d3bce

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

lib/client/cordova.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var coldstart = true;
22
var startupTime = new Date();
33
var startupThreshold = 1000; // ms
44
var paused = false;
5+
var waitingMessage = null;
56

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

92-
// Trigger notification
93-
onNotification(unifiedMessage);
93+
if (paused) {
94+
waitingMessage = unifiedMessage;
95+
} else {
96+
// Trigger notification
97+
onNotification(unifiedMessage);
98+
}
9499
};
95100

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

133-
// Trigger notification
134-
onNotification(unifiedMessage);
138+
if (paused) {
139+
waitingMessage = unifiedMessage;
140+
} else {
141+
// Trigger notification
142+
onNotification(unifiedMessage);
143+
}
135144
break;
136145

137146
case 'error':
@@ -232,6 +241,14 @@ Push.Configure = function(options) {
232241
paused = false;
233242
// Reset startup time at resume
234243
startupTime = new Date();
244+
245+
if (waitingMessage) {
246+
// Trigger notification
247+
onNotification(waitingMessage);
248+
249+
// Reset waiting message
250+
waitingMessage = null;
251+
}
235252
});
236253

237254
var pushNotification = window.plugins.pushNotification;

0 commit comments

Comments
 (0)