@@ -9,15 +9,15 @@ const PackageMixins = require("./package-mixins")(NativeCodePush);
9
9
async function checkForUpdate ( deploymentKey = null ) {
10
10
/*
11
11
* Before we ask the server if an update exists, we
12
- * need to retrieve three pieces of information from the
12
+ * need to retrieve three pieces of information from the
13
13
* native side: deployment key, app version (e.g. 1.0.1)
14
14
* and the hash of the currently running update (if there is one).
15
15
* This allows the client to only receive updates which are targetted
16
16
* for their specific deployment and version and which are actually
17
17
* different from the CodePush update they have already installed.
18
18
*/
19
19
const nativeConfig = await getConfiguration ( ) ;
20
-
20
+
21
21
/*
22
22
* If a deployment key was explicitly provided,
23
23
* then let's override the one we retrieved
@@ -30,7 +30,7 @@ async function checkForUpdate(deploymentKey = null) {
30
30
31
31
// Use dynamically overridden getCurrentPackage() during tests.
32
32
const localPackage = await module . exports . getCurrentPackage ( ) ;
33
-
33
+
34
34
/*
35
35
* If the app has a previously installed update, and that update
36
36
* was targetted at the same app version that is currently running,
@@ -48,9 +48,9 @@ async function checkForUpdate(deploymentKey = null) {
48
48
queryPackage . packageHash = config . packageHash ;
49
49
}
50
50
}
51
-
51
+
52
52
const update = await sdk . queryUpdateWithCurrentPackage ( queryPackage ) ;
53
-
53
+
54
54
/*
55
55
* There are four cases where checkForUpdate will resolve to null:
56
56
* ----------------------------------------------------------------
@@ -69,13 +69,13 @@ async function checkForUpdate(deploymentKey = null) {
69
69
* because we want to avoid having to install diff updates against the binary's
70
70
* version, which we can't do yet on Android.
71
71
*/
72
- if ( ! update || update . updateAppVersion ||
73
- localPackage && ( update . packageHash === localPackage . packageHash ) ||
72
+ if ( ! update || update . updateAppVersion ||
73
+ localPackage && ( update . packageHash === localPackage . packageHash ) ||
74
74
( ! localPackage || localPackage . _isDebugOnly ) && config . packageHash === update . packageHash ) {
75
75
if ( update && update . updateAppVersion ) {
76
76
log ( "An update is available but it is targeting a newer binary version than you are currently running." ) ;
77
77
}
78
-
78
+
79
79
return null ;
80
80
} else {
81
81
const remotePackage = { ...update , ...PackageMixins . remote ( sdk . reportStatusDownload ) } ;
@@ -93,7 +93,7 @@ const getConfiguration = (() => {
93
93
} else if ( testConfig ) {
94
94
return testConfig ;
95
95
} else {
96
- config = await NativeCodePush . getConfiguration ( ) ;
96
+ config = await NativeCodePush . getConfiguration ( ) ;
97
97
return config ;
98
98
}
99
99
}
@@ -123,7 +123,7 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
123
123
} else {
124
124
resolve ( update ) ;
125
125
}
126
- } ) ;
126
+ } ) ;
127
127
} ) ;
128
128
} ;
129
129
@@ -135,7 +135,7 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
135
135
} else {
136
136
resolve ( ) ;
137
137
}
138
- } ) ;
138
+ } ) ;
139
139
} ) ;
140
140
} ;
141
141
@@ -147,7 +147,7 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
147
147
} else {
148
148
resolve ( ) ;
149
149
}
150
- } ) ;
150
+ } ) ;
151
151
} ) ;
152
152
} ;
153
153
@@ -159,21 +159,21 @@ function log(message) {
159
159
console . log ( `[CodePush] ${ message } ` )
160
160
}
161
161
162
- // This ensures that notifyApplicationReadyInternal is only called once
162
+ // This ensures that notifyApplicationReadyInternal is only called once
163
163
// in the lifetime of this module instance.
164
164
const notifyApplicationReady = ( ( ) => {
165
165
let notifyApplicationReadyPromise ;
166
166
return ( ) => {
167
167
if ( ! notifyApplicationReadyPromise ) {
168
168
notifyApplicationReadyPromise = notifyApplicationReadyInternal ( ) ;
169
169
}
170
-
170
+
171
171
return notifyApplicationReadyPromise ;
172
172
} ;
173
173
} ) ( ) ;
174
174
175
175
async function notifyApplicationReadyInternal ( ) {
176
- await NativeCodePush . notifyApplicationReady ( ) ;
176
+ await NativeCodePush . notifyApplicationReady ( ) ;
177
177
const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
178
178
if ( statusReport ) {
179
179
const config = await getConfiguration ( ) ;
@@ -208,15 +208,15 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
208
208
const sync = ( ( ) => {
209
209
let syncInProgress = false ;
210
210
const setSyncCompleted = ( ) => { syncInProgress = false ; } ;
211
-
211
+
212
212
return ( options = { } , syncStatusChangeCallback , downloadProgressCallback ) => {
213
213
if ( syncInProgress ) {
214
214
typeof syncStatusChangeCallback === "function"
215
215
? syncStatusChangeCallback ( CodePush . SyncStatus . SYNC_IN_PROGRESS )
216
216
: log ( "Sync already in progress." ) ;
217
217
return Promise . resolve ( CodePush . SyncStatus . SYNC_IN_PROGRESS ) ;
218
- }
219
-
218
+ }
219
+
220
220
syncInProgress = true ;
221
221
const syncPromise = syncInternal ( options , syncStatusChangeCallback , downloadProgressCallback ) ;
222
222
syncPromise
@@ -230,7 +230,7 @@ const sync = (() => {
230
230
/*
231
231
* The syncInternal method provides a simple, one-line experience for
232
232
* incorporating the check, download and installation of an update.
233
- *
233
+ *
234
234
* It simply composes the existing API methods together and adds additional
235
235
* support for respecting mandatory updates, ignoring previously failed
236
236
* releases, and displaying a standard confirmation UI to the end-user
@@ -245,9 +245,9 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
245
245
mandatoryInstallMode : CodePush . InstallMode . IMMEDIATE ,
246
246
minimumBackgroundDuration : 0 ,
247
247
updateDialog : null ,
248
- ...options
248
+ ...options
249
249
} ;
250
-
250
+
251
251
syncStatusChangeCallback = typeof syncStatusChangeCallback === "function"
252
252
? syncStatusChangeCallback
253
253
: ( syncStatus ) => {
@@ -271,7 +271,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
271
271
log ( "User cancelled the update." ) ;
272
272
break ;
273
273
case CodePush . SyncStatus . UPDATE_INSTALLED :
274
- /*
274
+ /*
275
275
* If the install mode is IMMEDIATE, this will not get returned as the
276
276
* app will be restarted to a new Javascript context.
277
277
*/
@@ -290,40 +290,34 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
290
290
break ;
291
291
}
292
292
} ;
293
-
294
- downloadProgressCallback = typeof downloadProgressCallback === "function"
295
- ? downloadProgressCallback
296
- : ( downloadProgress ) => {
297
- log ( `Expecting ${ downloadProgress . totalBytes } bytes, received ${ downloadProgress . receivedBytes } bytes.` ) ;
298
- } ;
299
-
293
+
300
294
try {
301
295
await CodePush . notifyApplicationReady ( ) ;
302
-
296
+
303
297
syncStatusChangeCallback ( CodePush . SyncStatus . CHECKING_FOR_UPDATE ) ;
304
298
const remotePackage = await checkForUpdate ( syncOptions . deploymentKey ) ;
305
-
299
+
306
300
const doDownloadAndInstall = async ( ) => {
307
301
syncStatusChangeCallback ( CodePush . SyncStatus . DOWNLOADING_PACKAGE ) ;
308
302
const localPackage = await remotePackage . download ( downloadProgressCallback ) ;
309
-
303
+
310
304
// Determine the correct install mode based on whether the update is mandatory or not.
311
305
resolvedInstallMode = localPackage . isMandatory ? syncOptions . mandatoryInstallMode : syncOptions . installMode ;
312
-
306
+
313
307
syncStatusChangeCallback ( CodePush . SyncStatus . INSTALLING_UPDATE ) ;
314
308
await localPackage . install ( resolvedInstallMode , syncOptions . minimumBackgroundDuration , ( ) => {
315
309
syncStatusChangeCallback ( CodePush . SyncStatus . UPDATE_INSTALLED ) ;
316
310
} ) ;
317
-
311
+
318
312
return CodePush . SyncStatus . UPDATE_INSTALLED ;
319
313
} ;
320
-
314
+
321
315
const updateShouldBeIgnored = remotePackage && ( remotePackage . failedInstall && syncOptions . ignoreFailedUpdates ) ;
322
316
if ( ! remotePackage || updateShouldBeIgnored ) {
323
317
if ( updateShouldBeIgnored ) {
324
318
log ( "An update is available, but it is being ignored due to having been previously rolled back." ) ;
325
319
}
326
-
320
+
327
321
syncStatusChangeCallback ( CodePush . SyncStatus . UP_TO_DATE ) ;
328
322
return CodePush . SyncStatus . UP_TO_DATE ;
329
323
} else if ( syncOptions . updateDialog ) {
@@ -334,24 +328,24 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
334
328
} else {
335
329
syncOptions . updateDialog = { ...CodePush . DEFAULT_UPDATE_DIALOG , ...syncOptions . updateDialog } ;
336
330
}
337
-
338
- return await new Promise ( ( resolve , reject ) => {
331
+
332
+ return await new Promise ( ( resolve , reject ) => {
339
333
let message = null ;
340
334
const dialogButtons = [ {
341
335
text : null ,
342
- onPress : async ( ) => {
336
+ onPress : async ( ) => {
343
337
resolve ( await doDownloadAndInstall ( ) ) ;
344
338
}
345
339
} ] ;
346
-
340
+
347
341
if ( remotePackage . isMandatory ) {
348
342
message = syncOptions . updateDialog . mandatoryUpdateMessage ;
349
343
dialogButtons [ 0 ] . text = syncOptions . updateDialog . mandatoryContinueButtonLabel ;
350
344
} else {
351
345
message = syncOptions . updateDialog . optionalUpdateMessage ;
352
- dialogButtons [ 0 ] . text = syncOptions . updateDialog . optionalInstallButtonLabel ;
346
+ dialogButtons [ 0 ] . text = syncOptions . updateDialog . optionalInstallButtonLabel ;
353
347
// Since this is an optional update, add another button
354
- // to allow the end-user to ignore it
348
+ // to allow the end-user to ignore it
355
349
dialogButtons . push ( {
356
350
text : syncOptions . updateDialog . optionalIgnoreButtonLabel ,
357
351
onPress : ( ) => {
@@ -360,13 +354,13 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
360
354
}
361
355
} ) ;
362
356
}
363
-
357
+
364
358
// If the update has a description, and the developer
365
359
// explicitly chose to display it, then set that as the message
366
360
if ( syncOptions . updateDialog . appendReleaseDescription && remotePackage . description ) {
367
- message += `${ syncOptions . updateDialog . descriptionPrefix } ${ remotePackage . description } ` ;
361
+ message += `${ syncOptions . updateDialog . descriptionPrefix } ${ remotePackage . description } ` ;
368
362
}
369
-
363
+
370
364
syncStatusChangeCallback ( CodePush . SyncStatus . AWAITING_USER_ACTION ) ;
371
365
Alert . alert ( syncOptions . updateDialog . title , message , dialogButtons ) ;
372
366
} ) ;
@@ -375,16 +369,16 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
375
369
}
376
370
} catch ( error ) {
377
371
syncStatusChangeCallback ( CodePush . SyncStatus . UNKNOWN_ERROR ) ;
378
- log ( error . message ) ;
372
+ log ( error . message ) ;
379
373
throw error ;
380
- }
374
+ }
381
375
} ;
382
376
383
377
let CodePush ;
384
378
385
- // If the "NativeCodePush" variable isn't defined, then
379
+ // If the "NativeCodePush" variable isn't defined, then
386
380
// the app didn't properly install the native module,
387
- // and therefore, it doesn't make sense initializing
381
+ // and therefore, it doesn't make sense initializing
388
382
// the JS interface when it wouldn't work anyways.
389
383
if ( NativeCodePush ) {
390
384
CodePush = {
0 commit comments