@@ -466,16 +466,22 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
466466 }
467467 } ;
468468
469+ let remotePackageLabel ;
469470 try {
470471 await CodePush . notifyApplicationReady ( ) ;
471472
472473 syncStatusChangeCallback ( CodePush . SyncStatus . CHECKING_FOR_UPDATE ) ;
473474 const remotePackage = await checkForUpdate ( handleBinaryVersionMismatchCallback ) ;
475+ remotePackageLabel = remotePackage . label ;
474476
475477 const doDownloadAndInstall = async ( ) => {
476478 syncStatusChangeCallback ( CodePush . SyncStatus . DOWNLOADING_PACKAGE ) ;
479+ sharedCodePushOptions . onDownloadStart ?. ( remotePackageLabel ) ;
480+
477481 const localPackage = await remotePackage . download ( downloadProgressCallback ) ;
478482
483+ sharedCodePushOptions . onDownloadSuccess ?. ( remotePackageLabel ) ;
484+
479485 // Determine the correct install mode based on whether the update is mandatory or not.
480486 resolvedInstallMode = localPackage . isMandatory ? syncOptions . mandatoryInstallMode : syncOptions . installMode ;
481487
@@ -558,6 +564,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
558564 }
559565 } catch ( error ) {
560566 syncStatusChangeCallback ( CodePush . SyncStatus . UNKNOWN_ERROR ) ;
567+ sharedCodePushOptions ?. onSyncError ( remotePackageLabel ?? 'unknown' , error ) ;
561568 log ( error . message ) ;
562569 throw error ;
563570 }
@@ -584,12 +591,24 @@ let CodePush;
584591 * @type {{
585592 * releaseHistoryFetcher: releaseHistoryFetcher | undefined,
586593 * setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
594+ *
587595 * updateChecker: updateChecker | undefined,
588596 * setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
597+ *
589598 * onUpdateSuccess: (label: string) => void | undefined,
590599 * setOnUpdateSuccess(onUpdateSuccessFunction: (label: string) => void | undefined): void,
600+ *
591601 * onUpdateRollback: (label: string) => void | undefined,
592602 * 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,
593612 * }}
594613 */
595614const sharedCodePushOptions = {
@@ -616,6 +635,24 @@ const sharedCodePushOptions = {
616635 if ( typeof onUpdateRollbackFunction !== 'function' ) throw new Error ( 'Please pass a function to onUpdateRollback' ) ;
617636 this . onUpdateRollback = onUpdateRollbackFunction ;
618637 } ,
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+ } ,
619656}
620657
621658function codePushify ( options = { } ) {
@@ -648,6 +685,9 @@ function codePushify(options = {}) {
648685 // set telemetry callbacks
649686 sharedCodePushOptions . setOnUpdateSuccess ( options . onUpdateSuccess ) ;
650687 sharedCodePushOptions . setOnUpdateRollback ( options . onUpdateRollback ) ;
688+ sharedCodePushOptions . setOnDownloadStart ( options . onDownloadStart ) ;
689+ sharedCodePushOptions . setOnDownloadSuccess ( options . onDownloadSuccess ) ;
690+ sharedCodePushOptions . setOnSyncError ( options . onSyncError ) ;
651691
652692 const decorator = ( RootComponent ) => {
653693 class CodePushComponent extends React . Component {
0 commit comments