@@ -466,16 +466,22 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
466
466
}
467
467
} ;
468
468
469
+ let remotePackageLabel ;
469
470
try {
470
471
await CodePush . notifyApplicationReady ( ) ;
471
472
472
473
syncStatusChangeCallback ( CodePush . SyncStatus . CHECKING_FOR_UPDATE ) ;
473
474
const remotePackage = await checkForUpdate ( handleBinaryVersionMismatchCallback ) ;
475
+ remotePackageLabel = remotePackage . label ;
474
476
475
477
const doDownloadAndInstall = async ( ) => {
476
478
syncStatusChangeCallback ( CodePush . SyncStatus . DOWNLOADING_PACKAGE ) ;
479
+ sharedCodePushOptions . onDownloadStart ?. ( remotePackageLabel ) ;
480
+
477
481
const localPackage = await remotePackage . download ( downloadProgressCallback ) ;
478
482
483
+ sharedCodePushOptions . onDownloadSuccess ?. ( remotePackageLabel ) ;
484
+
479
485
// Determine the correct install mode based on whether the update is mandatory or not.
480
486
resolvedInstallMode = localPackage . isMandatory ? syncOptions . mandatoryInstallMode : syncOptions . installMode ;
481
487
@@ -558,6 +564,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
558
564
}
559
565
} catch ( error ) {
560
566
syncStatusChangeCallback ( CodePush . SyncStatus . UNKNOWN_ERROR ) ;
567
+ sharedCodePushOptions ?. onSyncError ( remotePackageLabel ?? 'unknown' , error ) ;
561
568
log ( error . message ) ;
562
569
throw error ;
563
570
}
@@ -584,12 +591,24 @@ let CodePush;
584
591
* @type {{
585
592
* releaseHistoryFetcher: releaseHistoryFetcher | undefined,
586
593
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
594
+ *
587
595
* updateChecker: updateChecker | undefined,
588
596
* setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
597
+ *
589
598
* onUpdateSuccess: (label: string) => void | undefined,
590
599
* setOnUpdateSuccess(onUpdateSuccessFunction: (label: string) => void | undefined): void,
600
+ *
591
601
* onUpdateRollback: (label: string) => void | undefined,
592
602
* setOnUpdateRollback(onUpdateRollbackFunction: (label: string) => void | undefined): void,
603
+ *
604
+ * onDownloadStart: (label: string) => void | undefined,
605
+ * setOnDownloadStart(onDownloadStartFunction: (label: string) => void | undefined): void,
606
+ *
607
+ * onDownloadSuccess: (label: string) => void | undefined,
608
+ * setOnDownloadSuccess(onDownloadSuccessFunction: (label: string) => void | undefined): void,
609
+ *
610
+ * onSyncError: (label: string, error: Error) => void | undefined,
611
+ * setOnSyncError(onSyncErrorFunction: (label: string, error: Error) => void | undefined): void,
593
612
* }}
594
613
*/
595
614
const sharedCodePushOptions = {
@@ -616,6 +635,24 @@ const sharedCodePushOptions = {
616
635
if ( typeof onUpdateRollbackFunction !== 'function' ) throw new Error ( 'Please pass a function to onUpdateRollback' ) ;
617
636
this . onUpdateRollback = onUpdateRollbackFunction ;
618
637
} ,
638
+ onDownloadStart : undefined ,
639
+ setOnDownloadStart ( onDownloadStartFunction ) {
640
+ if ( ! onDownloadStartFunction ) return ;
641
+ if ( typeof onDownloadStartFunction !== 'function' ) throw new Error ( 'Please pass a function to onDownloadStart' ) ;
642
+ this . onDownloadStart = onDownloadStartFunction ;
643
+ } ,
644
+ onDownloadSuccess : undefined ,
645
+ setOnDownloadSuccess ( onDownloadSuccessFunction ) {
646
+ if ( ! onDownloadSuccessFunction ) return ;
647
+ if ( typeof onDownloadSuccessFunction !== 'function' ) throw new Error ( 'Please pass a function to onDownloadSuccess' ) ;
648
+ this . onDownloadSuccess = onDownloadSuccessFunction ;
649
+ } ,
650
+ onSyncError : undefined ,
651
+ setOnSyncError ( onSyncErrorFunction ) {
652
+ if ( ! onSyncErrorFunction ) return ;
653
+ if ( typeof onSyncErrorFunction !== 'function' ) throw new Error ( 'Please pass a function to onSyncError' ) ;
654
+ this . onSyncError = onSyncErrorFunction ;
655
+ } ,
619
656
}
620
657
621
658
function codePushify ( options = { } ) {
@@ -648,6 +685,9 @@ function codePushify(options = {}) {
648
685
// set telemetry callbacks
649
686
sharedCodePushOptions . setOnUpdateSuccess ( options . onUpdateSuccess ) ;
650
687
sharedCodePushOptions . setOnUpdateRollback ( options . onUpdateRollback ) ;
688
+ sharedCodePushOptions . setOnDownloadStart ( options . onDownloadStart ) ;
689
+ sharedCodePushOptions . setOnDownloadSuccess ( options . onDownloadSuccess ) ;
690
+ sharedCodePushOptions . setOnSyncError ( options . onSyncError ) ;
651
691
652
692
const decorator = ( RootComponent ) => {
653
693
class CodePushComponent extends React . Component {
0 commit comments