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

Fix usage of removed method AppState.removeEventListener #2385

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions CodePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async function notifyApplicationReadyInternal() {
return statusReport;
}

async function tryReportStatus(statusReport, resumeListener) {
async function tryReportStatus(statusReport, retryOnAppResume) {
const config = await getConfiguration();
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
Expand Down Expand Up @@ -209,22 +209,21 @@ async function tryReportStatus(statusReport, resumeListener) {
}

NativeCodePush.recordStatusReported(statusReport);
resumeListener && AppState.removeEventListener("change", resumeListener);
retryOnAppResume && retryOnAppResume.remove();
} catch (e) {
log(`Report status failed: ${JSON.stringify(statusReport)}`);
NativeCodePush.saveStatusReportForRetry(statusReport);
// Try again when the app resumes
if (!resumeListener) {
resumeListener = async (newState) => {
if (!retryOnAppResume) {
const resumeListener = AppState.addEventListener("change", async (newState) => {
if (newState !== "active") return;
const refreshedStatusReport = await NativeCodePush.getNewStatusReport();
if (refreshedStatusReport) {
tryReportStatus(refreshedStatusReport, resumeListener);
} else {
AppState.removeEventListener("change", resumeListener);
resumeListener && resumeListener.remove();
}
};
AppState.addEventListener("change", resumeListener);
});
}
}
}
Expand Down