ionic-native
Version:
Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support
205 lines • 10.2 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var plugin_1 = require('./plugin');
/**
* Defines the possible result statuses of the window.codePush.sync operation.
*/
(function (SyncStatus) {
/**
* The application is up to date.
*/
SyncStatus[SyncStatus["UP_TO_DATE"] = 0] = "UP_TO_DATE";
/**
* 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.
*/
SyncStatus[SyncStatus["UPDATE_INSTALLED"] = 1] = "UPDATE_INSTALLED";
/**
* An optional update is available, but the user declined to install it. The update was not downloaded.
*/
SyncStatus[SyncStatus["UPDATE_IGNORED"] = 2] = "UPDATE_IGNORED";
/**
* 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.
*/
SyncStatus[SyncStatus["ERROR"] = 3] = "ERROR";
/**
* There is an ongoing sync in progress, so this attempt to sync has been aborted.
*/
SyncStatus[SyncStatus["IN_PROGRESS"] = 4] = "IN_PROGRESS";
/**
* Intermediate status - the plugin is about to check for updates.
*/
SyncStatus[SyncStatus["CHECKING_FOR_UPDATE"] = 5] = "CHECKING_FOR_UPDATE";
/**
* Intermediate status - a user dialog is about to be displayed. This status will be reported only if user interaction is enabled.
*/
SyncStatus[SyncStatus["AWAITING_USER_ACTION"] = 6] = "AWAITING_USER_ACTION";
/**
* Intermediate status - the update package is about to be downloaded.
*/
SyncStatus[SyncStatus["DOWNLOADING_PACKAGE"] = 7] = "DOWNLOADING_PACKAGE";
/**
* Intermediate status - the update package is about to be installed.
*/
SyncStatus[SyncStatus["INSTALLING_UPDATE"] = 8] = "INSTALLING_UPDATE";
})(exports.SyncStatus || (exports.SyncStatus = {}));
var SyncStatus = exports.SyncStatus;
/**
* Defines the available install modes for updates.
*/
(function (InstallMode) {
/**
* The update will be applied to the running application immediately. The application will be reloaded with the new content immediately.
*/
InstallMode[InstallMode["IMMEDIATE"] = 0] = "IMMEDIATE";
/**
* The update is downloaded but not installed immediately. The new content will be available the next time the application is started.
*/
InstallMode[InstallMode["ON_NEXT_RESTART"] = 1] = "ON_NEXT_RESTART";
/**
* The udpate is downloaded but not installed immediately. The new content will be available the next time the application is resumed or restarted, whichever event happends first.
*/
InstallMode[InstallMode["ON_NEXT_RESUME"] = 2] = "ON_NEXT_RESUME";
})(exports.InstallMode || (exports.InstallMode = {}));
var InstallMode = exports.InstallMode;
/**
* @name CodePush
* @description
* CodePush plugin for Cordova by Microsoft that supports iOS and Android.
*
* For more info, please see https://github.com/ksachdeva/ionic2-code-push-example
*
* @usage
* ```typescript
* import { CodePush } from 'ionic-native';
*
* // note - mostly error & completed methods of observable will not fire
* // as syncStatus will contain the current state of the update
* CodePush.sync().subscribe((syncStatus) => console.log(syncStatus));
*
* const downloadProgress = (progress) => { console.log(`Downloaded ${progress.receivedBytes} of ${progress.totalBytes}`); }
* CodePush.sync({}, downloadProgress).subscribe((syncStatus) => console.log(syncStatus));
*
* ```
*/
var CodePush = (function () {
function CodePush() {
}
/**
* Get the current package information.
*
* @param packageSuccess Callback invoked with the currently deployed package information.
* @param packageError Optional callback invoked in case of an error.
* @returns {Promise<ILocalPackage>}
*/
CodePush.getCurrentPackage = function () {
return;
};
/**
* Gets the pending package information, if any. A pending package is one that has been installed but the application still runs the old code.
* This happends only after a package has been installed using ON_NEXT_RESTART or ON_NEXT_RESUME mode, but the application was not restarted/resumed yet.
* @returns {Promise<ILocalPackage>}
*/
CodePush.getPendingPackage = function () {
return;
};
/**
* Checks with the CodePush server if an update package is available for download.
*
* @param querySuccess Callback invoked in case of a successful response from the server.
* The callback takes one RemotePackage parameter. A non-null package is a valid update.
* A null package means the application is up to date for the current native application version.
* @param queryError Optional callback invoked in case of an error.
* @param deploymentKey Optional deployment key that overrides the config.xml setting.
* @returns {Promise<IRemotePackage>}
*/
CodePush.checkForUpdate = function (deploymentKey) {
return;
};
/**
* Notifies the plugin that the update operation succeeded and that the application is ready.
* Calling this function is required on the first run after an update. On every subsequent application run, calling this function is a noop.
* If using sync API, calling this function is not required since sync calls it internally.
*
* @param notifySucceeded Optional callback invoked if the plugin was successfully notified.
* @param notifyFailed Optional callback invoked in case of an error during notifying the plugin.
* @returns {Promise<void>}
*/
CodePush.notifyApplicationReady = function () {
return;
};
/**
* Reloads the application. If there is a pending update package installed using ON_NEXT_RESTART or ON_NEXT_RESUME modes, the update
* will be immediately visible to the user. Otherwise, calling this function will simply reload the current version of the application.
* @returns {Promise<void>}
*/
CodePush.restartApplication = function () {
return;
};
/**
* Convenience method for installing updates in one method call.
* This method is provided for simplicity, and its behavior can be replicated by using window.codePush.checkForUpdate(), RemotePackage's download() and LocalPackage's install() methods.
*
* The algorithm of this method is the following:
* - Checks for an update on the CodePush server.
* - If an update is available
* - If the update is mandatory and the alertMessage is set in options, the user will be informed that the application will be updated to the latest version.
* The update package will then be downloaded and applied.
* - If the update is not mandatory and the confirmMessage is set in options, the user will be asked if they want to update to the latest version.
* If they decline, the syncCallback will be invoked with SyncStatus.UPDATE_IGNORED.
* - Otherwise, the update package will be downloaded and applied with no user interaction.
* - If no update is available on the server, or if a previously rolled back update is available and the ignoreFailedUpdates is set to true, the syncCallback will be invoked with the SyncStatus.UP_TO_DATE.
* - If an error occurs during checking for update, downloading or installing it, the syncCallback will be invoked with the SyncStatus.ERROR.
*
* @param syncCallback Optional callback to be called with the status of the sync operation.
* @param syncOptions Optional SyncOptions parameter configuring the behavior of the sync operation.
* @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.
* @returns {Observable<SyncStatus>}
*
*/
CodePush.sync = function (syncOptions, downloadProgress) {
return;
};
__decorate([
plugin_1.Cordova()
], CodePush, "getCurrentPackage", null);
__decorate([
plugin_1.Cordova()
], CodePush, "getPendingPackage", null);
__decorate([
plugin_1.Cordova({
callbackOrder: 'reverse'
})
], CodePush, "checkForUpdate", null);
__decorate([
plugin_1.Cordova()
], CodePush, "notifyApplicationReady", null);
__decorate([
plugin_1.Cordova()
], CodePush, "restartApplication", null);
__decorate([
plugin_1.Cordova({
observable: true,
successIndex: 0,
errorIndex: 3 // we don't need this, so we set it to a value higher than # of args
})
], CodePush, "sync", null);
CodePush = __decorate([
plugin_1.Plugin({
pluginName: 'CodePush',
plugin: 'cordova-plugin-code-push',
pluginRef: 'codePush',
repo: 'https://github.com/Microsoft/cordova-plugin-code-push',
platforms: ['Android', 'iOS']
})
], CodePush);
return CodePush;
}());
exports.CodePush = CodePush;
//# sourceMappingURL=code-push.js.map
;