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

Commit 2043e29

Browse files
committed
Revert "update JS"
This reverts commit b038fb4.
1 parent b038fb4 commit 2043e29

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

CodePush.js

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -159,62 +159,59 @@ function log(message) {
159159
console.log(`[CodePush] ${message}`)
160160
}
161161

162-
// This ensures that the native call to notifyApplicationReady
163-
// only happens once in the lifetime of this module instance.
162+
// This ensures that notifyApplicationReadyInternal is only called once
163+
// in the lifetime of this module instance.
164164
const notifyApplicationReady = (() => {
165165
let notifyApplicationReadyPromise;
166166
return () => {
167167
if (!notifyApplicationReadyPromise) {
168-
notifyApplicationReadyPromise = NativeCodePush.notifyApplicationReady();
168+
notifyApplicationReadyPromise = notifyApplicationReadyInternal();
169169
}
170170

171-
return notifyApplicationReadyPromise
172-
.then(() => {
173-
tryReportStatus();
174-
});
171+
return notifyApplicationReadyPromise;
175172
};
176173
})();
177174

178-
let tryReportStatus = (function() {
179-
let resumeListener;
180-
return async function () {
181-
const statusReport = await NativeCodePush.getNewStatusReport();
182-
if (statusReport) {
183-
const config = await getConfiguration();
184-
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
185-
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
186-
try {
187-
if (statusReport.appVersion) {
188-
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
189-
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
190-
} else {
191-
config.deploymentKey = statusReport.package.deploymentKey;
192-
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
193-
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
194-
}
175+
async function notifyApplicationReadyInternal() {
176+
await NativeCodePush.notifyApplicationReady();
177+
tryReportStatus();
178+
}
195179

196-
log(`Reported status: ${JSON.stringify(statusReport)}`);
197-
NativeCodePush.recordStatusReported(statusReport);
198-
resumeListener && AppState.removeEventListener("change", resumeListener);
199-
resumeListener = null;
200-
} catch (e) {
201-
log(`Report status failed: ${JSON.stringify(statusReport)}`);
202-
NativeCodePush.saveStatusReportForRetry(statusReport);
203-
// Try again when the app resumes
204-
if (!resumeListener) {
205-
resumeListener = (newState) => {
206-
newState === "active" && tryReportStatus(resumeListener);
207-
};
208-
209-
AppState.addEventListener("change", resumeListener);
210-
}
180+
async function tryReportStatus(resumeListener) {
181+
const statusReport = await NativeCodePush.getNewStatusReport();
182+
if (statusReport) {
183+
const config = await getConfiguration();
184+
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
185+
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
186+
try {
187+
if (statusReport.appVersion) {
188+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
189+
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
190+
} else {
191+
config.deploymentKey = statusReport.package.deploymentKey;
192+
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
193+
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
211194
}
212-
} else {
195+
196+
log(`Reported status: ${JSON.stringify(statusReport)}`);
197+
NativeCodePush.recordStatusReported(statusReport);
213198
resumeListener && AppState.removeEventListener("change", resumeListener);
214-
resumeListener = null;
199+
} catch (e) {
200+
log(`Report status failed: ${JSON.stringify(statusReport)}`);
201+
NativeCodePush.saveStatusReportForRetry(statusReport);
202+
// Try again when the app resumes
203+
if (!resumeListener) {
204+
resumeListener = (newState) => {
205+
newState === "active" && tryReportStatus(resumeListener);
206+
};
207+
208+
AppState.addEventListener("change", resumeListener);
209+
}
215210
}
211+
} else {
212+
resumeListener && AppState.removeEventListener("change", resumeListener);
216213
}
217-
})();
214+
}
218215

219216
function restartApp(onlyIfUpdateIsPending = false) {
220217
NativeCodePush.restartApp(onlyIfUpdateIsPending);

0 commit comments

Comments
 (0)