Revert "update JS"

This reverts commit b038fb493f.
This commit is contained in:
Geoffrey Goh
2016-05-10 15:26:36 -07:00
parent b038fb493f
commit 2043e296ac

View File

@@ -159,62 +159,59 @@ function log(message) {
console.log(`[CodePush] ${message}`)
}
// This ensures that the native call to notifyApplicationReady
// only happens once in the lifetime of this module instance.
// This ensures that notifyApplicationReadyInternal is only called once
// in the lifetime of this module instance.
const notifyApplicationReady = (() => {
let notifyApplicationReadyPromise;
return () => {
if (!notifyApplicationReadyPromise) {
notifyApplicationReadyPromise = NativeCodePush.notifyApplicationReady();
notifyApplicationReadyPromise = notifyApplicationReadyInternal();
}
return notifyApplicationReadyPromise
.then(() => {
tryReportStatus();
});
return notifyApplicationReadyPromise;
};
})();
let tryReportStatus = (function() {
let resumeListener;
return async function () {
const statusReport = await NativeCodePush.getNewStatusReport();
if (statusReport) {
const config = await getConfiguration();
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
try {
if (statusReport.appVersion) {
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
} else {
config.deploymentKey = statusReport.package.deploymentKey;
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
}
async function notifyApplicationReadyInternal() {
await NativeCodePush.notifyApplicationReady();
tryReportStatus();
}
log(`Reported status: ${JSON.stringify(statusReport)}`);
NativeCodePush.recordStatusReported(statusReport);
resumeListener && AppState.removeEventListener("change", resumeListener);
resumeListener = null;
} catch (e) {
log(`Report status failed: ${JSON.stringify(statusReport)}`);
NativeCodePush.saveStatusReportForRetry(statusReport);
// Try again when the app resumes
if (!resumeListener) {
resumeListener = (newState) => {
newState === "active" && tryReportStatus(resumeListener);
};
AppState.addEventListener("change", resumeListener);
}
async function tryReportStatus(resumeListener) {
const statusReport = await NativeCodePush.getNewStatusReport();
if (statusReport) {
const config = await getConfiguration();
const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
try {
if (statusReport.appVersion) {
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
} else {
config.deploymentKey = statusReport.package.deploymentKey;
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
}
} else {
log(`Reported status: ${JSON.stringify(statusReport)}`);
NativeCodePush.recordStatusReported(statusReport);
resumeListener && AppState.removeEventListener("change", resumeListener);
resumeListener = null;
} catch (e) {
log(`Report status failed: ${JSON.stringify(statusReport)}`);
NativeCodePush.saveStatusReportForRetry(statusReport);
// Try again when the app resumes
if (!resumeListener) {
resumeListener = (newState) => {
newState === "active" && tryReportStatus(resumeListener);
};
AppState.addEventListener("change", resumeListener);
}
}
} else {
resumeListener && AppState.removeEventListener("change", resumeListener);
}
})();
}
function restartApp(onlyIfUpdateIsPending = false) {
NativeCodePush.restartApp(onlyIfUpdateIsPending);