From 40447454f050f805b4673bf797e4c6b71d9ac562 Mon Sep 17 00:00:00 2001 From: Daniel Lebu Date: Fri, 4 Dec 2015 00:31:10 -0800 Subject: [PATCH] Added intermediate SyncStatus callbacks. Updated samples and documentation. --- README.md | 2 +- bin/www/codePush.js | 6 ++++ samples/advanced/www/js/index.js | 2 +- samples/basic/www/js/index.js | 62 +++++++++++++++++++++----------- www/codePush.ts | 6 ++++ 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 27ad02ce..3f93cd32 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ Interface defining several options for customizing the [sync](#codepushsync) ope - __installMode__: Used to specity the InstallMode used for the install operation. This is optional and defaults to InstallMode.ON_NEXT_RESTART. - __ignoreFailedUpdates__: Optional boolean flag. If set, updates available on the server for which and update was attempted and rolled back will be ignored. Defaults to true. (boolean) - __updatedialog__: Option used to enable, disable or customize the user interaction during sync. If set to false, user interaction will be disabled. If set to true, the user will be alerted or asked to confirm new updates, based on whether the update is mandatory. To customize the user dialog, this option can be set to a custom UpdateDialogOptions instance. - +- __deploymentKey__: Option used to override the config.xml deployment key when checking for updates. ### UpdateDialogOptions Interface defining the configuration options for the alert or confirmation dialog. diff --git a/bin/www/codePush.js b/bin/www/codePush.js index dc5e483d..38301a80 100644 --- a/bin/www/codePush.js +++ b/bin/www/codePush.js @@ -110,9 +110,11 @@ var CodePush = (function () { syncCallback && syncCallback(SyncStatus.UPDATE_INSTALLED); }; var onDownloadSuccess = function (localPackage) { + syncCallback && syncCallback(SyncStatus.INSTALLING_UPDATE); localPackage.install(onInstallSuccess, onError, syncOptions); }; var downloadAndInstallUpdate = function (remotePackage) { + syncCallback && syncCallback(SyncStatus.DOWNLOADING_PACKAGE); remotePackage.download(onDownloadSuccess, onError, downloadProgress); }; var onUpdate = function (remotePackage) { @@ -121,6 +123,9 @@ var CodePush = (function () { } else { var dlgOpts = syncOptions.updateDialog; + if (dlgOpts) { + syncCallback && syncCallback(SyncStatus.AWAITING_USER_ACTION); + } if (remotePackage.isMandatory && syncOptions.updateDialog) { var message = dlgOpts.appendReleaseDescription ? dlgOpts.mandatoryUpdateMessage + dlgOpts.descriptionPrefix + remotePackage.description @@ -149,6 +154,7 @@ var CodePush = (function () { } } }; + syncCallback && syncCallback(SyncStatus.CHECKING_FOR_UPDATE); window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey); }; CodePush.prototype.getDefaultSyncOptions = function () { diff --git a/samples/advanced/www/js/index.js b/samples/advanced/www/js/index.js index f12027bc..299e83b2 100644 --- a/samples/advanced/www/js/index.js +++ b/samples/advanced/www/js/index.js @@ -115,7 +115,7 @@ var app = { }; console.log("Installing package..."); - localPackage.install(installCallback, app.getErrorHandler("Installation failed.")); + localPackage.install(installCallback, app.getErrorHandler("Installation failed."), { installMode: InstallMode.IMMEDIATE }); }, // Returns an error handler that logs the error to the console and displays a notification containing the error message. getErrorHandler: function (message) { diff --git a/samples/basic/www/js/index.js b/samples/basic/www/js/index.js index 016ea7e5..17537387 100644 --- a/samples/basic/www/js/index.js +++ b/samples/basic/www/js/index.js @@ -33,28 +33,50 @@ var app = { // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function () { - /* Invoke sync with the default options, which enables user interaction. + + /* Invoke sync with the custom options, which enables user interaction. For customizing the sync behavior, see SyncOptions in the CodePush documentation. */ - window.codePush.sync(function (syncStatus) { - switch (syncStatus) { - case SyncStatus.UPDATE_INSTALLED: - console.log("The update was applied successfully. This is the last callback before the application is reloaded with the updated content."); - /* Don't continue app initialization, the application will refresh after this return. */ - return; - case SyncStatus.UP_TO_DATE: - app.displayMessage("The application is up to date."); - break; - case SyncStatus.UPDATE_IGNORED: - app.displayMessage("The user decided not to install the optional update."); - break; - case SyncStatus.ERROR: - app.displayMessage("An error occured while checking for updates"); - break; - } + window.codePush.sync( + function (syncStatus) { + switch (syncStatus) { + // Result (final) statuses + case SyncStatus.UPDATE_INSTALLED: + app.displayMessage("The update was installed successfully. For InstallMode.ON_NEXT_RESTART, the changes will be visible after application restart. "); + break; + case SyncStatus.UP_TO_DATE: + app.displayMessage("The application is up to date."); + break; + case SyncStatus.UPDATE_IGNORED: + app.displayMessage("The user decided not to install the optional update."); + break; + case SyncStatus.ERROR: + app.displayMessage("An error occured while checking for updates"); + break; + + // Intermediate (non final) statuses + case SyncStatus.CHECKING_FOR_UPDATE: + console.log("Checking for update."); + break; + case SyncStatus.AWAITING_USER_ACTION: + console.log("Alerting user."); + break; + case SyncStatus.DOWNLOADING_PACKAGE: + console.log("Downloading package."); + break; + case SyncStatus.INSTALLING_UPDATE: + console.log("Installing update"); + break; + } + }, + { + installMode: InstallMode.ON_NEXT_RESTART, updateDialog: true + }, + function (downloadProgress) { + console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes + " bytes."); + }); - // continue application initialization - app.receivedEvent('deviceready'); - }); + // continue application initialization + app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function (id) { diff --git a/www/codePush.ts b/www/codePush.ts index 199c9a23..01bb19a2 100644 --- a/www/codePush.ts +++ b/www/codePush.ts @@ -179,10 +179,12 @@ class CodePush implements CodePushCordovaPlugin { }; var onDownloadSuccess = (localPackage: ILocalPackage) => { + syncCallback && syncCallback(SyncStatus.INSTALLING_UPDATE); localPackage.install(onInstallSuccess, onError, syncOptions); }; var downloadAndInstallUpdate = (remotePackage: RemotePackage) => { + syncCallback && syncCallback(SyncStatus.DOWNLOADING_PACKAGE); remotePackage.download(onDownloadSuccess, onError, downloadProgress); }; @@ -191,6 +193,9 @@ class CodePush implements CodePushCordovaPlugin { syncCallback && syncCallback(SyncStatus.UP_TO_DATE); } else { var dlgOpts: UpdateDialogOptions = syncOptions.updateDialog; + if (dlgOpts) { + syncCallback && syncCallback(SyncStatus.AWAITING_USER_ACTION); + } if (remotePackage.isMandatory && syncOptions.updateDialog) { /* Alert user */ var message = dlgOpts.appendReleaseDescription ? @@ -224,6 +229,7 @@ class CodePush implements CodePushCordovaPlugin { } }; + syncCallback && syncCallback(SyncStatus.CHECKING_FOR_UPDATE); window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey); }