Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 26634c0

Browse files
committed
Expose the status report when calling notifyAppReady
1 parent c861d0c commit 26634c0

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

CodePush.js

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -172,50 +172,41 @@ const notifyApplicationReady = (() => {
172172

173173
async function notifyApplicationReadyInternal() {
174174
await NativeCodePush.notifyApplicationReady();
175-
tryReportStatus();
175+
const statusReport = await NativeCodePush.getNewStatusReport();
176+
tryReportStatus(statusReport); // Don't wait for this to complete.
177+
178+
return statusReport;
176179
}
177180

178-
async function tryReportStatus(resumeListener) {
179-
const statusReport = await NativeCodePush.getNewStatusReport();
180-
if (statusReport) {
181-
const config = await getConfiguration();
182-
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
183-
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
184-
try {
185-
if (statusReport.appVersion) {
186-
log(`Reporting binary update (${statusReport.appVersion})`);
187-
188-
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
189-
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
181+
async function tryReportStatus(statusReport) {
182+
if (!statusReport) return;
183+
184+
const config = await getConfiguration();
185+
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
186+
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
187+
try {
188+
if (statusReport.appVersion) {
189+
log(`Reporting binary update (${statusReport.appVersion})`);
190+
191+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
192+
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
193+
} else {
194+
const label = statusReport.package.label;
195+
if (statusReport.status === "DeploymentSucceeded") {
196+
log(`Reporting CodePush update success (${label})`);
190197
} else {
191-
const label = statusReport.package.label;
192-
if (statusReport.status === "DeploymentSucceeded") {
193-
log(`Reporting CodePush update success (${label})`);
194-
} else {
195-
log(`Reporting CodePush update rollback (${label})`);
196-
}
197-
198-
config.deploymentKey = statusReport.package.deploymentKey;
199-
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
200-
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
201-
}
202-
203-
NativeCodePush.recordStatusReported(statusReport);
204-
resumeListener && AppState.removeEventListener("change", resumeListener);
205-
} catch (e) {
206-
log(`Report status failed: ${JSON.stringify(statusReport)}`);
207-
NativeCodePush.saveStatusReportForRetry(statusReport);
208-
// Try again when the app resumes
209-
if (!resumeListener) {
210-
resumeListener = (newState) => {
211-
newState === "active" && tryReportStatus(resumeListener);
212-
};
213-
214-
AppState.addEventListener("change", resumeListener);
198+
log(`Reporting CodePush update rollback (${label})`);
215199
}
200+
201+
config.deploymentKey = statusReport.package.deploymentKey;
202+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
203+
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
216204
}
217-
} else {
218-
resumeListener && AppState.removeEventListener("change", resumeListener);
205+
206+
NativeCodePush.recordStatusReported(statusReport);
207+
} catch (e) {
208+
log(`Report status failed: ${JSON.stringify(statusReport)}`);
209+
NativeCodePush.saveStatusReportForRetry(statusReport);
219210
}
220211
}
221212

0 commit comments

Comments
 (0)