Added support for download progress notifications. Renamed SyncStatus.APPLY_SUCCESS to SyncStatus.UPDATE_INSTALLED.
This commit is contained in:
Родитель
f2ea35405a
Коммит
9965901f49
|
@ -175,7 +175,7 @@ Contains details about an update package that is available for download.
|
|||
Defines the possible result statuses of the [sync](#codepushsync) operation.
|
||||
### Properties
|
||||
- __UP_TO_DATE__: The application is up to date. (number)
|
||||
- __APPLY_SUCCESS__: An update is available, it has been downloaded, unzipped and copied to the deployment folder. After the completion of the callback invoked with SyncStatus.APPLY_SUCCESS, the application will be reloaded with the updated code and resources. (number)
|
||||
- __UPDATE_INSTALLED__: An update is available, it has been downloaded, unzipped and copied to the deployment folder. After the completion of the callback invoked with SyncStatus.UPDATE_INSTALLED, the application will be reloaded with the updated code and resources. (number)
|
||||
- __UPDATE_IGNORED__: An optional update is available, but the user declined to install it. The update was not downloaded. (number)
|
||||
- __ERROR__: An error happened during the sync operation. This might be an error while communicating with the server, downloading or unziping the update. The console logs should contain more information about what happened. No update has been applied in this case. (number)
|
||||
|
||||
|
@ -327,7 +327,7 @@ Interface defining several options for customizing the [sync](#codepushsync) ope
|
|||
|
||||
window.codePush.sync(function (syncStatus) {
|
||||
switch (syncStatus) {
|
||||
case SyncStatus.APPLY_SUCCESS:
|
||||
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;
|
||||
|
@ -362,7 +362,7 @@ var syncOptions = {
|
|||
|
||||
window.codePush.sync(function (syncStatus) {
|
||||
switch (syncStatus) {
|
||||
case SyncStatus.APPLY_SUCCESS:
|
||||
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;
|
||||
|
|
|
@ -109,7 +109,7 @@ var CodePush = (function () {
|
|||
syncCallback && syncCallback(SyncStatus.ERROR);
|
||||
};
|
||||
var onApplySuccess = function () {
|
||||
syncCallback && syncCallback(SyncStatus.APPLY_SUCCESS);
|
||||
syncCallback && syncCallback(SyncStatus.UPDATE_INSTALLED);
|
||||
};
|
||||
var onDownloadSuccess = function (localPackage) {
|
||||
localPackage.apply(onApplySuccess, onError, syncOptions.rollbackTimeout);
|
||||
|
|
|
@ -25,7 +25,7 @@ var RemotePackage = (function (_super) {
|
|||
function RemotePackage() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
RemotePackage.prototype.download = function (successCallback, errorCallback) {
|
||||
RemotePackage.prototype.download = function (successCallback, errorCallback, downloadProgress) {
|
||||
var _this = this;
|
||||
try {
|
||||
CodePushUtil.logMessage("Downloading update package ...");
|
||||
|
@ -59,6 +59,12 @@ var RemotePackage = (function (_super) {
|
|||
_this.currentFileTransfer = null;
|
||||
CodePushUtil.invokeErrorCallback(new Error(error.body), errorCallback);
|
||||
};
|
||||
this.currentFileTransfer.onprogress = function (progressEvent) {
|
||||
if (downloadProgress) {
|
||||
var dp = { receivedBytes: progressEvent.loaded, totalBytes: progressEvent.total };
|
||||
downloadProgress(dp);
|
||||
}
|
||||
};
|
||||
this.currentFileTransfer.download(this.downloadUrl, cordova.file.dataDirectory + LocalPackage.DownloadDir + "/" + LocalPackage.PackageUpdateFileName, downloadSuccess, downloadError, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
var SyncStatus;
|
||||
(function (SyncStatus) {
|
||||
SyncStatus[SyncStatus["UP_TO_DATE"] = 0] = "UP_TO_DATE";
|
||||
SyncStatus[SyncStatus["APPLY_SUCCESS"] = 1] = "APPLY_SUCCESS";
|
||||
SyncStatus[SyncStatus["UPDATE_INSTALLED"] = 1] = "UPDATE_INSTALLED";
|
||||
SyncStatus[SyncStatus["UPDATE_IGNORED"] = 2] = "UPDATE_IGNORED";
|
||||
SyncStatus[SyncStatus["ERROR"] = 3] = "ERROR";
|
||||
})(SyncStatus || (SyncStatus = {}));
|
||||
|
|
|
@ -37,7 +37,7 @@ var app = {
|
|||
For customizing the sync behavior, see SyncOptions in the CodePush documentation. */
|
||||
window.codePush.sync(function (syncStatus) {
|
||||
switch (syncStatus) {
|
||||
case SyncStatus.APPLY_SUCCESS:
|
||||
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;
|
||||
|
|
|
@ -24,7 +24,7 @@ export class TestMessage {
|
|||
public static CHECK_ERROR = "CHECK_ERROR";
|
||||
public static DOWNLOAD_SUCCEEDED = "DOWNLOAD_SUCCEEDED";
|
||||
public static DOWNLOAD_ERROR = "DOWNLOAD_ERROR";
|
||||
public static APPLY_SUCCESS = "APPLY_SUCCESS";
|
||||
public static UPDATE_INSTALLED = "UPDATE_INSTALLED";
|
||||
public static APPLY_ERROR = "APPLY_ERROR";
|
||||
public static DEVICE_READY_AFTER_UPDATE = "DEVICE_READY_AFTER_UPDATE";
|
||||
public static UPDATE_FAILED_PREVIOUSLY = "UPDATE_FAILED_PREVIOUSLY";
|
||||
|
@ -34,7 +34,7 @@ export class TestMessage {
|
|||
public static SYNC_STATUS = "SYNC_STATUS";
|
||||
|
||||
public static SYNC_UP_TO_DATE = 0;
|
||||
public static SYNC_APPLY_SUCCESS = 1;
|
||||
public static SYNC_UPDATE_INSTALLED = 1;
|
||||
public static SYNC_UPDATE_IGNORED = 2;
|
||||
public static SYNC_ERROR = 3;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ var app = {
|
|||
app.sendTestMessage("DOWNLOAD_ERROR");
|
||||
},
|
||||
applySuccess: function () {
|
||||
console.log("Apply success.");
|
||||
app.sendTestMessage("APPLY_SUCCESS");
|
||||
console.log("Update installed.");
|
||||
app.sendTestMessage("UPDATE_INSTALLED");
|
||||
},
|
||||
applyError: function (error) {
|
||||
console.log("Apply error.");
|
||||
|
|
|
@ -50,7 +50,7 @@ var app = {
|
|||
},
|
||||
applySuccess: function () {
|
||||
console.log("Apply success.");
|
||||
app.sendTestMessage("APPLY_SUCCESS");
|
||||
app.sendTestMessage("UPDATE_INSTALLED");
|
||||
},
|
||||
applyError: function (error) {
|
||||
console.log("Apply error.");
|
||||
|
|
14
test/test.ts
14
test/test.ts
|
@ -366,7 +366,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([su.TestMessage.APPLY_SUCCESS, su.TestMessage.DEVICE_READY_AFTER_UPDATE], deferred);
|
||||
testMessageCallback = verifyMessages([su.TestMessage.UPDATE_INSTALLED, su.TestMessage.DEVICE_READY_AFTER_UPDATE], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -395,7 +395,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([su.TestMessage.APPLY_SUCCESS, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.UPDATE_FAILED_PREVIOUSLY], deferred);
|
||||
testMessageCallback = verifyMessages([su.TestMessage.UPDATE_INSTALLED, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.UPDATE_FAILED_PREVIOUSLY], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -405,7 +405,7 @@ describe("window.codePush", function() {
|
|||
console.log("Creating a second failed update.");
|
||||
var deferred = Q.defer<void>();
|
||||
mockResponse = { updateInfo: getMockResponse(true) };
|
||||
testMessageCallback = verifyMessages([su.TestMessage.APPLY_SUCCESS, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.UPDATE_FAILED_PREVIOUSLY], deferred);
|
||||
testMessageCallback = verifyMessages([su.TestMessage.UPDATE_INSTALLED, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.UPDATE_FAILED_PREVIOUSLY], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -423,7 +423,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([su.TestMessage.APPLY_SUCCESS, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.NOTIFY_APP_READY_SUCCESS, su.TestMessage.APPLICATION_NOT_REVERTED], deferred);
|
||||
testMessageCallback = verifyMessages([su.TestMessage.UPDATE_INSTALLED, su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.NOTIFY_APP_READY_SUCCESS, su.TestMessage.APPLICATION_NOT_REVERTED], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -505,7 +505,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_APPLY_SUCCESS]), su.TestMessage.DEVICE_READY_AFTER_UPDATE], deferred);
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_UPDATE_INSTALLED]), su.TestMessage.DEVICE_READY_AFTER_UPDATE], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -534,7 +534,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_APPLY_SUCCESS]), su.TestMessage.DEVICE_READY_AFTER_UPDATE, new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_UP_TO_DATE])], deferred);
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_UPDATE_INSTALLED]), su.TestMessage.DEVICE_READY_AFTER_UPDATE, new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_UP_TO_DATE])], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
@ -552,7 +552,7 @@ describe("window.codePush", function() {
|
|||
.then<void>((updatePath: string) => {
|
||||
var deferred = Q.defer<void>();
|
||||
mockUpdatePackagePath = updatePath;
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_APPLY_SUCCESS]), su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.APPLICATION_NOT_REVERTED], deferred);
|
||||
testMessageCallback = verifyMessages([new su.AppMessage(su.TestMessage.SYNC_STATUS, [su.TestMessage.SYNC_UPDATE_INSTALLED]), su.TestMessage.DEVICE_READY_AFTER_UPDATE, su.TestMessage.APPLICATION_NOT_REVERTED], deferred);
|
||||
console.log("Running project...");
|
||||
projectManager.runPlatform(testRunDirectory, targetPlatform, true, targetEmulator);
|
||||
return deferred.promise;
|
||||
|
|
|
@ -56,8 +56,9 @@ interface IRemotePackage extends IPackage {
|
|||
*
|
||||
* @param downloadSuccess Called with one parameter, the downloaded package information, once the download completed successfully.
|
||||
* @param downloadError Optional callback invoked in case of an error.
|
||||
* @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.
|
||||
*/
|
||||
download(downloadSuccess: SuccessCallback<ILocalPackage>, downloadError?: ErrorCallback): void;
|
||||
download(downloadSuccess: SuccessCallback<ILocalPackage>, downloadError?: ErrorCallback, downloadProgress?: SuccessCallback<DownloadProgress>): void;
|
||||
|
||||
/**
|
||||
* Aborts the current download session, previously started with download().
|
||||
|
@ -216,9 +217,9 @@ declare enum SyncStatus {
|
|||
|
||||
/**
|
||||
* An update is available, it has been downloaded, unzipped and copied to the deployment folder.
|
||||
* After the completion of the callback invoked with SyncStatus.APPLY_SUCCESS, the application will be reloaded with the updated code and resources.
|
||||
* After the completion of the callback invoked with SyncStatus.UPDATE_INSTALLED, the application will be reloaded with the updated code and resources.
|
||||
*/
|
||||
APPLY_SUCCESS,
|
||||
UPDATE_INSTALLED,
|
||||
|
||||
/**
|
||||
* An optional update is available, but the user declined to install it. The update was not downloaded.
|
||||
|
@ -296,4 +297,12 @@ interface SyncOptions {
|
|||
*/
|
||||
interface IDiffManifest {
|
||||
deletedFiles: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the format of the DownloadProgress object, used to send periodical update notifications on the progress of the update download.
|
||||
*/
|
||||
interface DownloadProgress {
|
||||
totalBytes: number;
|
||||
receivedBytes: number;
|
||||
}
|
|
@ -169,7 +169,7 @@ class CodePush implements CodePushCordovaPlugin {
|
|||
};
|
||||
|
||||
var onApplySuccess = () => {
|
||||
syncCallback && syncCallback(SyncStatus.APPLY_SUCCESS);
|
||||
syncCallback && syncCallback(SyncStatus.UPDATE_INSTALLED);
|
||||
};
|
||||
|
||||
var onDownloadSuccess = (localPackage: ILocalPackage) => {
|
||||
|
|
|
@ -27,8 +27,9 @@ class RemotePackage extends Package implements IRemotePackage {
|
|||
*
|
||||
* @param downloadSuccess Called with one parameter, the downloaded package information, once the download completed successfully.
|
||||
* @param downloadError Optional callback invoked in case of an error.
|
||||
* @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.
|
||||
*/
|
||||
public download(successCallback: SuccessCallback<LocalPackage>, errorCallback?: ErrorCallback): void {
|
||||
public download(successCallback: SuccessCallback<LocalPackage>, errorCallback?: ErrorCallback, downloadProgress?: SuccessCallback<DownloadProgress>): void {
|
||||
try {
|
||||
CodePushUtil.logMessage("Downloading update package ...");
|
||||
if (!this.downloadUrl) {
|
||||
|
@ -65,6 +66,13 @@ class RemotePackage extends Package implements IRemotePackage {
|
|||
this.currentFileTransfer = null;
|
||||
CodePushUtil.invokeErrorCallback(new Error(error.body), errorCallback);
|
||||
};
|
||||
|
||||
this.currentFileTransfer.onprogress = (progressEvent: ProgressEvent) => {
|
||||
if (downloadProgress) {
|
||||
var dp: DownloadProgress = { receivedBytes: progressEvent.loaded, totalBytes: progressEvent.total };
|
||||
downloadProgress(dp);
|
||||
}
|
||||
};
|
||||
|
||||
this.currentFileTransfer.download(this.downloadUrl, cordova.file.dataDirectory + LocalPackage.DownloadDir + "/" + LocalPackage.PackageUpdateFileName, downloadSuccess, downloadError, true);
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ enum SyncStatus {
|
|||
|
||||
/**
|
||||
* An update is available, it has been downloaded, unzipped and copied to the deployment folder.
|
||||
* After the completion of the callback invoked with SyncStatus.APPLY_SUCCESS, the application will be reloaded with the updated code and resources.
|
||||
* After the completion of the callback invoked with SyncStatus.UPDATE_INSTALLED, the application will be reloaded with the updated code and resources.
|
||||
*/
|
||||
APPLY_SUCCESS,
|
||||
UPDATE_INSTALLED,
|
||||
|
||||
/**
|
||||
* An optional update is available, but the user declined to install it. The update was not downloaded.
|
||||
|
|
Загрузка…
Ссылка в новой задаче