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

Commit 6b4459e

Browse files
committed
Fix module initialization
1 parent 5160ee1 commit 6b4459e

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

CodePush.js

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function checkForUpdate(deploymentKey = null) {
2727
* deployments (e.g. an early access deployment for insiders).
2828
*/
2929
const config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig;
30+
3031
const sdk = getPromisifiedSdk(requestFetchAdapter, config);
3132

3233
// Use dynamically overridden getCurrentPackage() during tests.
@@ -368,42 +369,52 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
368369
}
369370
};
370371

371-
const CodePush = {
372-
AcquisitionSdk: Sdk,
373-
checkForUpdate,
374-
getConfiguration,
375-
getCurrentPackage,
376-
log,
377-
notifyApplicationReady,
378-
restartApp,
379-
setUpTestDependencies,
380-
sync,
381-
InstallMode: {
382-
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
383-
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
384-
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
385-
},
386-
SyncStatus: {
387-
CHECKING_FOR_UPDATE: 0,
388-
AWAITING_USER_ACTION: 1,
389-
DOWNLOADING_PACKAGE: 2,
390-
INSTALLING_UPDATE: 3,
391-
UP_TO_DATE: 4, // The running app is up-to-date
392-
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
393-
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
394-
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
395-
UNKNOWN_ERROR: -1
396-
},
397-
DEFAULT_UPDATE_DIALOG: {
398-
appendReleaseDescription: false,
399-
descriptionPrefix: " Description: ",
400-
mandatoryContinueButtonLabel: "Continue",
401-
mandatoryUpdateMessage: "An update is available that must be installed.",
402-
optionalIgnoreButtonLabel: "Ignore",
403-
optionalInstallButtonLabel: "Install",
404-
optionalUpdateMessage: "An update is available. Would you like to install it?",
405-
title: "Update available"
406-
}
407-
};
372+
let CodePush;
373+
374+
// If the "NativeCodePush" variable isn't defined, then
375+
// the app didn't properly install the native module,
376+
// and therefore, it doesn't make sense initializing
377+
// the the JS interface when it wouldn't work anyways.
378+
if (NativeCodePush) {
379+
CodePush = {
380+
AcquisitionSdk: Sdk,
381+
checkForUpdate,
382+
getConfiguration,
383+
getCurrentPackage,
384+
log,
385+
notifyApplicationReady,
386+
restartApp,
387+
setUpTestDependencies,
388+
sync,
389+
InstallMode: {
390+
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
391+
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
392+
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
393+
},
394+
SyncStatus: {
395+
CHECKING_FOR_UPDATE: 0,
396+
AWAITING_USER_ACTION: 1,
397+
DOWNLOADING_PACKAGE: 2,
398+
INSTALLING_UPDATE: 3,
399+
UP_TO_DATE: 4, // The running app is up-to-date
400+
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
401+
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
402+
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
403+
UNKNOWN_ERROR: -1
404+
},
405+
DEFAULT_UPDATE_DIALOG: {
406+
appendReleaseDescription: false,
407+
descriptionPrefix: " Description: ",
408+
mandatoryContinueButtonLabel: "Continue",
409+
mandatoryUpdateMessage: "An update is available that must be installed.",
410+
optionalIgnoreButtonLabel: "Ignore",
411+
optionalInstallButtonLabel: "Install",
412+
optionalUpdateMessage: "An update is available. Would you like to install it?",
413+
title: "Update available"
414+
}
415+
}
416+
} else {
417+
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.");
418+
}
408419

409420
module.exports = CodePush;

0 commit comments

Comments
 (0)