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

Commit 848a961

Browse files
authored
Merge pull request #379 from convoyinc/nevir/status-report
Expose status reports via notifyAppReady()
2 parents 4987d45 + 0683720 commit 848a961

File tree

2 files changed

+151
-102
lines changed

2 files changed

+151
-102
lines changed

CodePush.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -172,50 +172,53 @@ 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, resumeListener) {
182+
const config = await getConfiguration();
183+
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
184+
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
185+
try {
186+
if (statusReport.appVersion) {
187+
log(`Reporting binary update (${statusReport.appVersion})`);
188+
189+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
190+
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
191+
} else {
192+
const label = statusReport.package.label;
193+
if (statusReport.status === "DeploymentSucceeded") {
194+
log(`Reporting CodePush update success (${label})`);
190195
} 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);
196+
log(`Reporting CodePush update rollback (${label})`);
215197
}
198+
199+
config.deploymentKey = statusReport.package.deploymentKey;
200+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
201+
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
216202
}
217-
} else {
203+
204+
NativeCodePush.recordStatusReported(statusReport);
218205
resumeListener && AppState.removeEventListener("change", resumeListener);
206+
} catch (e) {
207+
log(`Report status failed: ${JSON.stringify(statusReport)}`);
208+
NativeCodePush.saveStatusReportForRetry(statusReport);
209+
// Try again when the app resumes
210+
if (!resumeListener) {
211+
resumeListener = async (newState) => {
212+
if (newState !== "active") return;
213+
const refreshedStatusReport = await NativeCodePush.getNewStatusReport();
214+
if (refreshedStatusReport) {
215+
tryReportStatus(refreshedStatusReport, resumeListener);
216+
} else {
217+
AppState.removeEventListener("change", resumeListener);
218+
}
219+
};
220+
AppState.addEventListener("change", resumeListener);
221+
}
219222
}
220223
}
221224

@@ -438,6 +441,10 @@ if (NativeCodePush) {
438441
PENDING: NativeCodePush.codePushUpdateStatePending,
439442
LATEST: NativeCodePush.codePushUpdateStateLatest
440443
},
444+
DeploymentStatus: {
445+
FAILED: "DeploymentFailed",
446+
SUCCEEDED: "DeploymentSucceeded",
447+
},
441448
DEFAULT_UPDATE_DIALOG: {
442449
appendReleaseDescription: false,
443450
descriptionPrefix: " Description: ",

0 commit comments

Comments
 (0)