@@ -159,62 +159,59 @@ function log(message) {
159
159
console . log ( `[CodePush] ${ message } ` )
160
160
}
161
161
162
- // This ensures that the native call to notifyApplicationReady
163
- // only happens once in the lifetime of this module instance.
162
+ // This ensures that notifyApplicationReadyInternal is only called once
163
+ // in the lifetime of this module instance.
164
164
const notifyApplicationReady = ( ( ) => {
165
165
let notifyApplicationReadyPromise ;
166
166
return ( ) => {
167
167
if ( ! notifyApplicationReadyPromise ) {
168
- notifyApplicationReadyPromise = NativeCodePush . notifyApplicationReady ( ) ;
168
+ notifyApplicationReadyPromise = notifyApplicationReadyInternal ( ) ;
169
169
}
170
170
171
- return notifyApplicationReadyPromise
172
- . then ( ( ) => {
173
- tryReportStatus ( ) ;
174
- } ) ;
171
+ return notifyApplicationReadyPromise ;
175
172
} ;
176
173
} ) ( ) ;
177
174
178
- let tryReportStatus = ( function ( ) {
179
- let resumeListener ;
180
- return async function ( ) {
181
- const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
182
- if ( statusReport ) {
183
- const config = await getConfiguration ( ) ;
184
- const previousLabelOrAppVersion = statusReport . previousLabelOrAppVersion ;
185
- const previousDeploymentKey = statusReport . previousDeploymentKey || config . deploymentKey ;
186
- try {
187
- if ( statusReport . appVersion ) {
188
- const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
189
- await sdk . reportStatusDeploy ( /* deployedPackage */ null , /* status */ null , previousLabelOrAppVersion , previousDeploymentKey ) ;
190
- } else {
191
- config . deploymentKey = statusReport . package . deploymentKey ;
192
- const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
193
- await sdk . reportStatusDeploy ( statusReport . package , statusReport . status , previousLabelOrAppVersion , previousDeploymentKey ) ;
194
- }
175
+ async function notifyApplicationReadyInternal ( ) {
176
+ await NativeCodePush . notifyApplicationReady ( ) ;
177
+ tryReportStatus ( ) ;
178
+ }
195
179
196
- log ( `Reported status: ${ JSON . stringify ( statusReport ) } ` ) ;
197
- NativeCodePush . recordStatusReported ( statusReport ) ;
198
- resumeListener && AppState . removeEventListener ( "change" , resumeListener ) ;
199
- resumeListener = null ;
200
- } catch ( e ) {
201
- log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
202
- NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
203
- // Try again when the app resumes
204
- if ( ! resumeListener ) {
205
- resumeListener = ( newState ) => {
206
- newState === "active" && tryReportStatus ( resumeListener ) ;
207
- } ;
208
-
209
- AppState . addEventListener ( "change" , resumeListener ) ;
210
- }
180
+ async function tryReportStatus ( resumeListener ) {
181
+ const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
182
+ if ( statusReport ) {
183
+ const config = await getConfiguration ( ) ;
184
+ const previousLabelOrAppVersion = statusReport . previousLabelOrAppVersion ;
185
+ const previousDeploymentKey = statusReport . previousDeploymentKey || config . deploymentKey ;
186
+ try {
187
+ if ( statusReport . appVersion ) {
188
+ const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
189
+ await sdk . reportStatusDeploy ( /* deployedPackage */ null , /* status */ null , previousLabelOrAppVersion , previousDeploymentKey ) ;
190
+ } else {
191
+ config . deploymentKey = statusReport . package . deploymentKey ;
192
+ const sdk = getPromisifiedSdk ( requestFetchAdapter , config ) ;
193
+ await sdk . reportStatusDeploy ( statusReport . package , statusReport . status , previousLabelOrAppVersion , previousDeploymentKey ) ;
211
194
}
212
- } else {
195
+
196
+ log ( `Reported status: ${ JSON . stringify ( statusReport ) } ` ) ;
197
+ NativeCodePush . recordStatusReported ( statusReport ) ;
213
198
resumeListener && AppState . removeEventListener ( "change" , resumeListener ) ;
214
- resumeListener = null ;
199
+ } catch ( e ) {
200
+ log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
201
+ NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
202
+ // Try again when the app resumes
203
+ if ( ! resumeListener ) {
204
+ resumeListener = ( newState ) => {
205
+ newState === "active" && tryReportStatus ( resumeListener ) ;
206
+ } ;
207
+
208
+ AppState . addEventListener ( "change" , resumeListener ) ;
209
+ }
215
210
}
211
+ } else {
212
+ resumeListener && AppState . removeEventListener ( "change" , resumeListener ) ;
216
213
}
217
- } ) ( ) ;
214
+ }
218
215
219
216
function restartApp ( onlyIfUpdateIsPending = false ) {
220
217
NativeCodePush . restartApp ( onlyIfUpdateIsPending ) ;
0 commit comments