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

Commit 04e84b5

Browse files
committed
Bring back resumeListener
1 parent 5cc371f commit 04e84b5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

CodePush.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ async function notifyApplicationReadyInternal() {
178178
return statusReport;
179179
}
180180

181-
async function tryReportStatus(statusReport) {
182-
if (!statusReport) return;
183-
181+
async function tryReportStatus(statusReport, resumeListener) {
184182
const config = await getConfiguration();
185183
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
186184
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
@@ -204,9 +202,23 @@ async function tryReportStatus(statusReport) {
204202
}
205203

206204
NativeCodePush.recordStatusReported(statusReport);
205+
resumeListener && AppState.removeEventListener("change", resumeListener);
207206
} catch (e) {
208207
log(`Report status failed: ${JSON.stringify(statusReport)}`);
209208
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+
}
210222
}
211223
}
212224

0 commit comments

Comments
 (0)