@@ -172,50 +172,53 @@ const notifyApplicationReady = (() => {
172
172
173
173
async function notifyApplicationReadyInternal ( ) {
174
174
await NativeCodePush . notifyApplicationReady ( ) ;
175
- tryReportStatus ( ) ;
175
+ const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
176
+ tryReportStatus ( statusReport ) ; // Don't wait for this to complete.
177
+
178
+ return statusReport ;
176
179
}
177
180
178
- async function tryReportStatus ( resumeListener ) {
179
- const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
180
- if ( statusReport ) {
181
- const config = await getConfiguration ( ) ;
182
- const previousLabelOrAppVersion = statusReport . previousLabelOrAppVersion ;
183
- const previousDeploymentKey = statusReport . previousDeploymentKey || config . deploymentKey ;
184
- try {
185
- if ( statusReport . appVersion ) {
186
- log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
187
-
188
- const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
189
- await sdk . reportStatusDeploy ( /* deployedPackage */ null , /* status */ null , previousLabelOrAppVersion , previousDeploymentKey ) ;
181
+ async function tryReportStatus ( statusReport , resumeListener ) {
182
+ const config = await getConfiguration ( ) ;
183
+ const previousLabelOrAppVersion = statusReport . previousLabelOrAppVersion ;
184
+ const previousDeploymentKey = statusReport . previousDeploymentKey || config . deploymentKey ;
185
+ try {
186
+ if ( statusReport . appVersion ) {
187
+ log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
188
+
189
+ const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
190
+ await sdk . reportStatusDeploy ( /* deployedPackage */ null , /* status */ null , previousLabelOrAppVersion , previousDeploymentKey ) ;
191
+ } else {
192
+ const label = statusReport . package . label ;
193
+ if ( statusReport . status === "DeploymentSucceeded" ) {
194
+ log ( `Reporting CodePush update success (${ label } )` ) ;
190
195
} else {
191
- const label = statusReport . package . label ;
192
- if ( statusReport . status === "DeploymentSucceeded" ) {
193
- log ( `Reporting CodePush update success (${ label } )` ) ;
194
- } else {
195
- log ( `Reporting CodePush update rollback (${ label } )` ) ;
196
- }
197
-
198
- config . deploymentKey = statusReport . package . deploymentKey ;
199
- const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
200
- await sdk . reportStatusDeploy ( statusReport . package , statusReport . status , previousLabelOrAppVersion , previousDeploymentKey ) ;
201
- }
202
-
203
- NativeCodePush . recordStatusReported ( statusReport ) ;
204
- resumeListener && AppState . removeEventListener ( "change" , resumeListener ) ;
205
- } catch ( e ) {
206
- log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
207
- NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
208
- // Try again when the app resumes
209
- if ( ! resumeListener ) {
210
- resumeListener = ( newState ) => {
211
- newState === "active" && tryReportStatus ( resumeListener ) ;
212
- } ;
213
-
214
- AppState . addEventListener ( "change" , resumeListener ) ;
196
+ log ( `Reporting CodePush update rollback (${ label } )` ) ;
215
197
}
198
+
199
+ config . deploymentKey = statusReport . package . deploymentKey ;
200
+ const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
201
+ await sdk . reportStatusDeploy ( statusReport . package , statusReport . status , previousLabelOrAppVersion , previousDeploymentKey ) ;
216
202
}
217
- } else {
203
+
204
+ NativeCodePush . recordStatusReported ( statusReport ) ;
218
205
resumeListener && AppState . removeEventListener ( "change" , resumeListener ) ;
206
+ } catch ( e ) {
207
+ log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
208
+ NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
209
+ // Try again when the app resumes
210
+ if ( ! resumeListener ) {
211
+ resumeListener = async ( newState ) => {
212
+ if ( newState !== "active" ) return ;
213
+ const refreshedStatusReport = await NativeCodePush . getNewStatusReport ( ) ;
214
+ if ( refreshedStatusReport ) {
215
+ tryReportStatus ( refreshedStatusReport , resumeListener ) ;
216
+ } else {
217
+ AppState . removeEventListener ( "change" , resumeListener ) ;
218
+ }
219
+ } ;
220
+ AppState . addEventListener ( "change" , resumeListener ) ;
221
+ }
219
222
}
220
223
}
221
224
@@ -438,6 +441,10 @@ if (NativeCodePush) {
438
441
PENDING : NativeCodePush . codePushUpdateStatePending ,
439
442
LATEST : NativeCodePush . codePushUpdateStateLatest
440
443
} ,
444
+ DeploymentStatus : {
445
+ FAILED : "DeploymentFailed" ,
446
+ SUCCEEDED : "DeploymentSucceeded" ,
447
+ } ,
441
448
DEFAULT_UPDATE_DIALOG : {
442
449
appendReleaseDescription : false ,
443
450
descriptionPrefix : " Description: " ,
0 commit comments