From babb3c285ce1cd0d8e9316c2eacdbeb8d2b76a6e Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Mon, 26 Oct 2015 23:59:42 -0700 Subject: [PATCH 1/9] CodePush.sync implementation --- CodePush.ios.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 8555e10..e26b999 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -95,12 +95,52 @@ function notifyApplicationReady() { return NativeCodePush.notifyApplicationReady(); } +function sync(options = {}) { + return new Promise((resolve, reject) => { + checkForUpdate() + .then((remotePackage) => { + if (!remotePackage) { + resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); + } + else { + var dialogButtons = [ + { + text: options.downloadButtonText || "Download", + onPress: () => { + remotePackage.download() + .then((localPackage) => { + resolve(CodePush.SyncStatus.APPLY_SUCCESS); + localPackage.apply(options.rollbackTImeout); + }, reject); + } + } + ]; + + if (!remotePackage.isMandatory) { + dialogButtons.push({ + text: options.cancelButtonText || "Cancel", + onPress: () => resolve(CodePush.SyncStatus.USER_CANCELLED) + }); + } + + React.AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons); + } + }, reject); + }); +}; + var CodePush = { getConfiguration: getConfiguration, checkForUpdate: checkForUpdate, getCurrentPackage: getCurrentPackage, notifyApplicationReady: notifyApplicationReady, - setUpTestDependencies: setUpTestDependencies + setUpTestDependencies: setUpTestDependencies, + sync: sync, + SyncStatus: { + NO_UPDATE_AVAILABLE: 0, + APPLY_SUCCESS: 1, + USER_CANCELLED: 2 + } }; -module.exports = CodePush; +module.exports = CodePush; \ No newline at end of file From 1da068f275fa7e0e2cdcb5b9795f5de8397e57de Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 27 Oct 2015 00:01:55 -0700 Subject: [PATCH 2/9] Move React require to top --- CodePush.ios.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index e26b999..56b850d 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -10,6 +10,7 @@ var NativeCodePush = require('react-native').NativeModules.CodePush; var requestFetchAdapter = require("./request-fetch-adapter.js"); var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager; var packageMixins = require("./package-mixins")(NativeCodePush); +var { AlertIOS } = require("react-native"); // This function is only used for tests. Replaces the default SDK, configuration and native bridge function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge){ @@ -105,7 +106,7 @@ function sync(options = {}) { else { var dialogButtons = [ { - text: options.downloadButtonText || "Download", + text: options.updateButtonText || "Update", onPress: () => { remotePackage.download() .then((localPackage) => { @@ -118,12 +119,12 @@ function sync(options = {}) { if (!remotePackage.isMandatory) { dialogButtons.push({ - text: options.cancelButtonText || "Cancel", + text: options.cancelButtonText || "Ignore", onPress: () => resolve(CodePush.SyncStatus.USER_CANCELLED) }); } - React.AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons); + AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons); } }, reject); }); @@ -138,8 +139,8 @@ var CodePush = { sync: sync, SyncStatus: { NO_UPDATE_AVAILABLE: 0, - APPLY_SUCCESS: 1, - USER_CANCELLED: 2 + USER_CANCELLED: 1, + APPLY_SUCCESS: 2 } }; From cc6053381f95359ea069a8237fd31055ef06c3d1 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 27 Oct 2015 00:09:25 -0700 Subject: [PATCH 3/9] Rename cancel to ignore --- CodePush.ios.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 56b850d..e64e73c 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -119,12 +119,12 @@ function sync(options = {}) { if (!remotePackage.isMandatory) { dialogButtons.push({ - text: options.cancelButtonText || "Ignore", - onPress: () => resolve(CodePush.SyncStatus.USER_CANCELLED) + text: options.ignoreButtonText || "Ignore", + onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED) }); } - AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons); + AlertIOS.alert(options.updateTitle || "Update available", remotePackage.description, dialogButtons); } }, reject); }); @@ -139,7 +139,7 @@ var CodePush = { sync: sync, SyncStatus: { NO_UPDATE_AVAILABLE: 0, - USER_CANCELLED: 1, + UPDATE_IGNORED: 1, APPLY_SUCCESS: 2 } }; From 7b27896882d10b7d852702191ac024349b813b80 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 27 Oct 2015 00:24:43 -0700 Subject: [PATCH 4/9] Fixing typo and spacing --- CodePush.ios.js | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index e64e73c..3735f77 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -99,34 +99,34 @@ function notifyApplicationReady() { function sync(options = {}) { return new Promise((resolve, reject) => { checkForUpdate() - .then((remotePackage) => { - if (!remotePackage) { - resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); - } - else { - var dialogButtons = [ - { - text: options.updateButtonText || "Update", - onPress: () => { - remotePackage.download() - .then((localPackage) => { - resolve(CodePush.SyncStatus.APPLY_SUCCESS); - localPackage.apply(options.rollbackTImeout); - }, reject); - } - } - ]; - - if (!remotePackage.isMandatory) { - dialogButtons.push({ - text: options.ignoreButtonText || "Ignore", - onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED) - }); + .then((remotePackage) => { + if (!remotePackage) { + resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); } - - AlertIOS.alert(options.updateTitle || "Update available", remotePackage.description, dialogButtons); - } - }, reject); + else { + var dialogButtons = [ + { + text: options.updateButtonText || "Update", + onPress: () => { + remotePackage.download() + .then((localPackage) => { + resolve(CodePush.SyncStatus.APPLY_SUCCESS); + localPackage.apply(options.rollbackTimeout); + }, reject); + } + } + ]; + + if (!remotePackage.isMandatory) { + dialogButtons.push({ + text: options.ignoreButtonText || "Ignore", + onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED) + }); + } + + AlertIOS.alert(options.updateTitle || "Update available", remotePackage.description, dialogButtons); + } + }, reject); }); }; From 30b4abc680763935a123da482cd30bc3ff8066eb Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 28 Oct 2015 17:52:03 -0700 Subject: [PATCH 5/9] 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); }); From 9b68b54c0a5cf357f4b8750f7b1dc0ec3fceca19 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 28 Oct 2015 18:09:09 -0700 Subject: [PATCH 6/9] Adding some doc comments --- CodePush.ios.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 63f38d4..63ddc67 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -96,6 +96,15 @@ function notifyApplicationReady() { return NativeCodePush.notifyApplicationReady(); } +/** + * The sync method provides a simple, one-line experience for + * incorporating the check, download and application of an update. + * + * It simply composes the existing API methods together and adds additional + * support for respecting mandatory updates, ignoring previously failed + * releases, and displaying a standard confirmation UI to the end-user + * when an update is available. + */ function sync(options = {}) { var syncOptions = { ignoreFailedUpdates: true, @@ -139,8 +148,10 @@ function sync(options = {}) { dialogButtons[0].text = syncOptions.mandatoryContinueButtonLabel; } else { message = syncOptions.optionalUpdateMessage; - - dialogButtons[0].text = syncOptions.optionalInstallButtonLabel; + dialogButtons[0].text = syncOptions.optionalInstallButtonLabel; + + // Since this is an optional update, add another button + // to allow the end-user to ignore it dialogButtons.push({ text: syncOptions.optionalIgnoreButtonLabel, onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED) @@ -161,9 +172,9 @@ var CodePush = { setUpTestDependencies: setUpTestDependencies, sync: sync, SyncStatus: { - NO_UPDATE_AVAILABLE: 0, - UPDATE_IGNORED: 1, - APPLY_SUCCESS: 2 + NO_UPDATE_AVAILABLE: 0, // The running app is up-to-date + UPDATE_IGNORED: 1, // The app had an optional update and the end-user chose to ignore it + APPLY_SUCCESS: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be applied } }; From 0c5cb645dcd0e80edc9103169150d090a36e4aa3 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Thu, 29 Oct 2015 10:41:27 -0700 Subject: [PATCH 7/9] Adding new option and fixing some naming --- CodePush.ios.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 63ddc67..f058c78 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -110,15 +110,17 @@ function sync(options = {}) { ignoreFailedUpdates: true, mandatoryContinueButtonLabel: "Continue", - mandatoryUpdateMessage: "An update is available that must be installed", + 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, + updateTitle: "Update available", + useReleaseDescription: false, + ...options }; @@ -136,7 +138,7 @@ function sync(options = {}) { onPress: () => { remotePackage.download() .then((localPackage) => { - resolve(CodePush.SyncStatus.APPLY_SUCCESS); + resolve(CodePush.SyncStatus.UPDATE_DOWNLOADED); localPackage.apply(syncOptions.rollbackTimeout); }, reject); } @@ -158,7 +160,13 @@ function sync(options = {}) { }); } - AlertIOS.alert(syncOptions.updateTitle, message || remotePackage.description, dialogButtons); + // If the update has a description, and the developer + // explicitly chose to display it, then set that as the message + if (syncOptions.useReleaseDescription && remotePackage.description) { + message = remotePackage.description; + } + + AlertIOS.alert(syncOptions.updateTitle, message, dialogButtons); } }, reject); }); @@ -174,7 +182,7 @@ var CodePush = { SyncStatus: { NO_UPDATE_AVAILABLE: 0, // The running app is up-to-date UPDATE_IGNORED: 1, // The app had an optional update and the end-user chose to ignore it - APPLY_SUCCESS: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be applied + UPDATE_DOWNLOADED: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be applied } }; From 4968fe642c633b58d09c07951c7498e915aa7078 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Thu, 29 Oct 2015 10:42:25 -0700 Subject: [PATCH 8/9] Fixing typo --- CodePush.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index f058c78..77677f4 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -127,7 +127,7 @@ function sync(options = {}) { return new Promise((resolve, reject) => { checkForUpdate() .then((remotePackage) => { - if (!remotePackage || (remotePackage.failedAppy && syncOptions.ignoreFailedUpdates)) { + if (!remotePackage || (remotePackage.failedApply && syncOptions.ignoreFailedUpdates)) { resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); } else { From 9cef711f240b72d5a0150db0b723cffc5166ab44 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Thu, 29 Oct 2015 13:40:23 -0700 Subject: [PATCH 9/9] Adding new description prefix option --- CodePush.ios.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 77677f4..d643a44 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -107,6 +107,9 @@ function notifyApplicationReady() { */ function sync(options = {}) { var syncOptions = { + descriptionPrefix: " Description: ", + appendReleaseDescription: false, + ignoreFailedUpdates: true, mandatoryContinueButtonLabel: "Continue", @@ -119,7 +122,6 @@ function sync(options = {}) { rollbackTimeout: 0, updateTitle: "Update available", - useReleaseDescription: false, ...options }; @@ -128,7 +130,7 @@ function sync(options = {}) { checkForUpdate() .then((remotePackage) => { if (!remotePackage || (remotePackage.failedApply && syncOptions.ignoreFailedUpdates)) { - resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); + resolve(CodePush.SyncStatus.UP_TO_DATE); } else { var message = null; @@ -138,9 +140,11 @@ function sync(options = {}) { onPress: () => { remotePackage.download() .then((localPackage) => { - resolve(CodePush.SyncStatus.UPDATE_DOWNLOADED); - localPackage.apply(syncOptions.rollbackTimeout); - }, reject); + resolve(CodePush.SyncStatus.UPDATE_APPLIED) + return localPackage.apply(syncOptions.rollbackTimeout); + }) + .catch(reject) + .done(); } } ]; @@ -162,13 +166,15 @@ function sync(options = {}) { // If the update has a description, and the developer // explicitly chose to display it, then set that as the message - if (syncOptions.useReleaseDescription && remotePackage.description) { - message = remotePackage.description; + if (syncOptions.appendReleaseDescription && remotePackage.description) { + message += `${syncOptions.descriptionPrefix} ${remotePackage.description}`; } AlertIOS.alert(syncOptions.updateTitle, message, dialogButtons); } - }, reject); + }) + .catch(reject) + .done(); }); }; @@ -180,9 +186,9 @@ var CodePush = { setUpTestDependencies: setUpTestDependencies, sync: sync, SyncStatus: { - NO_UPDATE_AVAILABLE: 0, // The running app is up-to-date + UP_TO_DATE: 0, // The running app is up-to-date UPDATE_IGNORED: 1, // The app had an optional update and the end-user chose to ignore it - UPDATE_DOWNLOADED: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be applied + UPDATE_APPLIED: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be applied } };