1
1
import { AppState , type NativeEventSubscription } from 'react-native' ;
2
+ import { LogLevel } from './enums/LogLevel.enum' ;
2
3
import { CodePushApiSdk } from './internals/CodePushApiSdk' ;
3
4
import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule' ;
4
5
import { getConfiguration } from './internals/getConfiguration' ;
@@ -26,9 +27,17 @@ export const notifyAppReady = (() => {
26
27
} ) ( ) ;
27
28
28
29
async function notifyApplicationReadyInternal ( ) {
30
+ log ( LogLevel . DEBUG , 'notifyApplicationReady' ) ;
31
+
29
32
await NativeRNAppZungCodePushModule . notifyApplicationReady ( ) ;
30
33
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
+ }
32
41
33
42
return statusReport ;
34
43
}
@@ -39,7 +48,7 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
39
48
const previousReleaseChannelPublicId = statusReport . previousReleaseChannelPublicId || config . releaseChannelPublicId ;
40
49
try {
41
50
if ( statusReport . appVersion ) {
42
- log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
51
+ log ( LogLevel . INFO , `Reporting binary update (${ statusReport . appVersion } )` ) ;
43
52
44
53
if ( ! config . releaseChannelPublicId ) {
45
54
throw new Error ( 'Release channel is missing' ) ;
@@ -54,9 +63,9 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
54
63
55
64
const label = statusReport . package . label ;
56
65
if ( statusReport . status === 'DeploymentSucceeded' ) {
57
- log ( `Reporting CodePush update success (${ label } )` ) ;
66
+ log ( LogLevel . INFO , `Reporting CodePush update success (${ label } )` ) ;
58
67
} else {
59
- log ( `Reporting CodePush update rollback (${ label } )` ) ;
68
+ log ( LogLevel . INFO , `Reporting CodePush update rollback (${ label } )` ) ;
60
69
await NativeRNAppZungCodePushModule . setLatestRollbackInfo ( statusReport . package . packageHash ) ;
61
70
}
62
71
@@ -75,14 +84,15 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
75
84
NativeRNAppZungCodePushModule . recordStatusReported ( statusReport ) ;
76
85
retryOnAppResume && retryOnAppResume . remove ( ) ;
77
86
} catch ( e ) {
78
- log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
87
+ log ( LogLevel . WARN , `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
79
88
NativeRNAppZungCodePushModule . saveStatusReportForRetry ( statusReport ) ;
80
89
// Try again when the app resumes
81
90
if ( ! retryOnAppResume ) {
82
91
const resumeListener = AppState . addEventListener ( 'change' , async ( newState ) => {
83
92
if ( newState !== 'active' ) return ;
84
93
const refreshedStatusReport = await NativeRNAppZungCodePushModule . getNewStatusReport ( ) ;
85
94
if ( refreshedStatusReport ) {
95
+ log ( LogLevel . DEBUG , `tryReportStatus on active appState ${ statusReport . status || '(no update)' } ` ) ;
86
96
tryReportStatus ( refreshedStatusReport , resumeListener ) ;
87
97
} else {
88
98
resumeListener && resumeListener . remove ( ) ;
0 commit comments