From 30b4abc680763935a123da482cd30bc3ff8066eb Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 28 Oct 2015 17:52:03 -0700 Subject: [PATCH] Adding more sync options --- CodePush.ios.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 3735f77..63f38d4 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -97,34 +97,57 @@ function notifyApplicationReady() { } function sync(options = {}) { + var syncOptions = { + ignoreFailedUpdates: true, + + 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?", + + updateTitle: "Update available", + rollbackTimeout: 0, + + ...options + }; + return new Promise((resolve, reject) => { checkForUpdate() .then((remotePackage) => { - if (!remotePackage) { + if (!remotePackage || (remotePackage.failedAppy && syncOptions.ignoreFailedUpdates)) { resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); } else { + var message = null; var dialogButtons = [ { - text: options.updateButtonText || "Update", + text: null, onPress: () => { remotePackage.download() .then((localPackage) => { resolve(CodePush.SyncStatus.APPLY_SUCCESS); - localPackage.apply(options.rollbackTimeout); + localPackage.apply(syncOptions.rollbackTimeout); }, reject); } } ]; - if (!remotePackage.isMandatory) { + if (remotePackage.isMandatory) { + message = syncOptions.mandatoryUpdateMessage; + dialogButtons[0].text = syncOptions.mandatoryContinueButtonLabel; + } else { + message = syncOptions.optionalUpdateMessage; + + dialogButtons[0].text = syncOptions.optionalInstallButtonLabel; dialogButtons.push({ - text: options.ignoreButtonText || "Ignore", + text: syncOptions.optionalIgnoreButtonLabel, onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED) }); } - AlertIOS.alert(options.updateTitle || "Update available", remotePackage.description, dialogButtons); + AlertIOS.alert(syncOptions.updateTitle, message || remotePackage.description, dialogButtons); } }, reject); });