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

Commit 5c06b53

Browse files
committed
Merge pull request #215 from Microsoft/module_loading
Make loading our JS module more permissive
2 parents 5160ee1 + 6dadf82 commit 5c06b53

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

CodePush.js

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -368,42 +368,52 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
368368
}
369369
};
370370

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

409-
module.exports = CodePush;
419+
module.exports = CodePush;

0 commit comments

Comments
 (0)