From 6b4459e010c0edbb8e4ff75ae2003df804842e91 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Sat, 27 Feb 2016 14:39:55 -0800 Subject: [PATCH] Fix module initialization --- CodePush.js | 85 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/CodePush.js b/CodePush.js index 90889ac..a8ba462 100644 --- a/CodePush.js +++ b/CodePush.js @@ -27,6 +27,7 @@ async function checkForUpdate(deploymentKey = null) { * deployments (e.g. an early access deployment for insiders). */ const config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig; + const sdk = getPromisifiedSdk(requestFetchAdapter, config); // Use dynamically overridden getCurrentPackage() during tests. @@ -368,42 +369,52 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg } }; -const CodePush = { - AcquisitionSdk: Sdk, - checkForUpdate, - getConfiguration, - getCurrentPackage, - log, - notifyApplicationReady, - restartApp, - setUpTestDependencies, - sync, - InstallMode: { - IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately - ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart - ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background - }, - SyncStatus: { - CHECKING_FOR_UPDATE: 0, - AWAITING_USER_ACTION: 1, - DOWNLOADING_PACKAGE: 2, - INSTALLING_UPDATE: 3, - UP_TO_DATE: 4, // The running app is up-to-date - UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it - UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. - SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. - UNKNOWN_ERROR: -1 - }, - DEFAULT_UPDATE_DIALOG: { - appendReleaseDescription: false, - descriptionPrefix: " Description: ", - mandatoryContinueButtonLabel: "Continue", - mandatoryUpdateMessage: "An update is available that must be installed.", - optionalIgnoreButtonLabel: "Ignore", - optionalInstallButtonLabel: "Install", - optionalUpdateMessage: "An update is available. Would you like to install it?", - title: "Update available" - } -}; +let CodePush; + +// If the "NativeCodePush" variable isn't defined, then +// the app didn't properly install the native module, +// and therefore, it doesn't make sense initializing +// the the JS interface when it wouldn't work anyways. +if (NativeCodePush) { + CodePush = { + AcquisitionSdk: Sdk, + checkForUpdate, + getConfiguration, + getCurrentPackage, + log, + notifyApplicationReady, + restartApp, + setUpTestDependencies, + sync, + InstallMode: { + IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately + ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart + ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background + }, + SyncStatus: { + CHECKING_FOR_UPDATE: 0, + AWAITING_USER_ACTION: 1, + DOWNLOADING_PACKAGE: 2, + INSTALLING_UPDATE: 3, + UP_TO_DATE: 4, // The running app is up-to-date + UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it + UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. + SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. + UNKNOWN_ERROR: -1 + }, + DEFAULT_UPDATE_DIALOG: { + appendReleaseDescription: false, + descriptionPrefix: " Description: ", + mandatoryContinueButtonLabel: "Continue", + mandatoryUpdateMessage: "An update is available that must be installed.", + optionalIgnoreButtonLabel: "Ignore", + optionalInstallButtonLabel: "Install", + optionalUpdateMessage: "An update is available. Would you like to install it?", + title: "Update available" + } + } +} else { + log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly."); +} module.exports = CodePush; \ No newline at end of file