11import { AppState , type NativeEventSubscription } from 'react-native' ;
2+ import { LogLevel } from './enums/LogLevel.enum' ;
23import { CodePushApiSdk } from './internals/CodePushApiSdk' ;
34import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule' ;
45import { getConfiguration } from './internals/getConfiguration' ;
@@ -26,9 +27,17 @@ export const notifyAppReady = (() => {
2627} ) ( ) ;
2728
2829async function notifyApplicationReadyInternal ( ) {
30+ log ( LogLevel . DEBUG , 'notifyApplicationReady' ) ;
31+
2932 await NativeRNAppZungCodePushModule . notifyApplicationReady ( ) ;
3033 const statusReport = await NativeRNAppZungCodePushModule . getNewStatusReport ( ) ;
31- statusReport && tryReportStatus ( statusReport ) ; // Don't wait for this to complete.
34+ if ( statusReport ) {
35+ log ( LogLevel . DEBUG , `tryReportStatus ${ statusReport . status || '(no update)' } ` ) ;
36+
37+ tryReportStatus ( statusReport ) ; // Don't wait for this to complete.
38+ } else {
39+ log ( LogLevel . DEBUG , `Nothing to report` ) ;
40+ }
3241
3342 return statusReport ;
3443}
@@ -39,7 +48,7 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
3948 const previousReleaseChannelPublicId = statusReport . previousReleaseChannelPublicId || config . releaseChannelPublicId ;
4049 try {
4150 if ( statusReport . appVersion ) {
42- log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
51+ log ( LogLevel . INFO , `Reporting binary update (${ statusReport . appVersion } )` ) ;
4352
4453 if ( ! config . releaseChannelPublicId ) {
4554 throw new Error ( 'Release channel is missing' ) ;
@@ -54,9 +63,9 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
5463
5564 const label = statusReport . package . label ;
5665 if ( statusReport . status === 'DeploymentSucceeded' ) {
57- log ( `Reporting CodePush update success (${ label } )` ) ;
66+ log ( LogLevel . INFO , `Reporting CodePush update success (${ label } )` ) ;
5867 } else {
59- log ( `Reporting CodePush update rollback (${ label } )` ) ;
68+ log ( LogLevel . INFO , `Reporting CodePush update rollback (${ label } )` ) ;
6069 await NativeRNAppZungCodePushModule . setLatestRollbackInfo ( statusReport . package . packageHash ) ;
6170 }
6271
@@ -75,14 +84,15 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
7584 NativeRNAppZungCodePushModule . recordStatusReported ( statusReport ) ;
7685 retryOnAppResume && retryOnAppResume . remove ( ) ;
7786 } catch ( e ) {
78- log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
87+ log ( LogLevel . WARN , `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
7988 NativeRNAppZungCodePushModule . saveStatusReportForRetry ( statusReport ) ;
8089 // Try again when the app resumes
8190 if ( ! retryOnAppResume ) {
8291 const resumeListener = AppState . addEventListener ( 'change' , async ( newState ) => {
8392 if ( newState !== 'active' ) return ;
8493 const refreshedStatusReport = await NativeRNAppZungCodePushModule . getNewStatusReport ( ) ;
8594 if ( refreshedStatusReport ) {
95+ log ( LogLevel . DEBUG , `tryReportStatus on active appState ${ statusReport . status || '(no update)' } ` ) ;
8696 tryReportStatus ( refreshedStatusReport , resumeListener ) ;
8797 } else {
8898 resumeListener && resumeListener . remove ( ) ;
0 commit comments