Skip to content

Commit 04bdade

Browse files
committed
feat(hot code push): add update events
1 parent e7968da commit 04bdade

File tree

1 file changed

+140
-1
lines changed
  • src/@ionic-native/plugins/hot-code-push

1 file changed

+140
-1
lines changed

src/@ionic-native/plugins/hot-code-push/index.ts

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { Cordova, Plugin, IonicNativePlugin, CordovaCheck } from '@ionic-native/core';
3+
import { Observable } from 'rxjs/Observable';
34

45
declare var chcp: any;
56

@@ -48,6 +49,44 @@ export interface HotCodePushRequestOptions {
4849
'request-headers'?: {[key: string]: any};
4950
}
5051

52+
/**
53+
* For description on error codes, please visit https://github.com/nordnet/cordova-hot-code-push/wiki/Error-codes
54+
*/
55+
export enum ErrorCode {
56+
NOTHING_TO_INSTALL = 1,
57+
NOTHING_TO_UPDATE = 2,
58+
FAILED_TO_DOWNLOAD_APPLICATION_CONFIG = -1,
59+
APPLICATION_BUILD_VERSION_TOO_LOW = -2,
60+
FAILED_TO_DOWNLOAD_CONTENT_MANIFEST = -3,
61+
FAILED_TO_DOWNLOAD_UPDATE_FILES = -4,
62+
FAILED_TO_MOVE_LOADED_FILES_TO_INSTALLATION_FOLDER = -5,
63+
UPDATE_IS_INVALID = -6,
64+
FAILED_TO_COPY_FILES_FROM_PREVIOUS_RELEASE = -7,
65+
FAILED_TO_COPY_NEW_CONTENT_FILES = -8,
66+
LOCAL_VERSION_OF_APPLICATION_CONFIG_NOT_FOUND = -9,
67+
LOCAL_VERSION_OF_MANIFEST_NOT_FOUND = -10,
68+
LOADED_VERSION_OF_APPLICATION_CONFIG_NOT_FOUND = -11,
69+
LOADED_VERSION_OF_MANIFEST_NOT_FOUND = -12,
70+
FAILED_TO_INSTALL_ASSETS_ON_EXTERNAL_STORAGE = -13,
71+
CANT_INSTALL_WHILE_DOWNLOAD_IN_PROGRESS = -14,
72+
CANT_DOWNLOAD_UPDATE_WHILE_INSTALLATION_IN_PROGRESS = -15,
73+
INSTALLATION_ALREADY_IN_PROGRESS = -16,
74+
DOWNLOAD_ALREADY_IN_PROGRESS = -17,
75+
ASSETS_FOLDER_IS_NOT_YET_INSTALLED = -18,
76+
NEW_APPLICATION_CONFIG_IS_INVALID = -19
77+
}
78+
79+
export interface HotCodePushError {
80+
code: ErrorCode;
81+
description: string;
82+
}
83+
84+
export interface HotCodePushEventData {
85+
details?: {
86+
error?: HotCodePushError;
87+
};
88+
};
89+
5190
/**
5291
* @name Hot Code Push
5392
* @description
@@ -92,7 +131,7 @@ export class HotCodePush extends IonicNativePlugin {
92131
@CordovaCheck()
93132
fetchUpdate(options?: HotCodePushRequestOptions): Promise<any> {
94133
return new Promise<any>((resolve, reject) => {
95-
HotCodePush.getPlugin().fetchUpdate((error: any, data: any) => {
134+
HotCodePush.getPlugin().fetchUpdate((error: HotCodePushError, data: any) => {
96135
if (error) {
97136
reject(error);
98137
} else {
@@ -128,4 +167,104 @@ export class HotCodePush extends IonicNativePlugin {
128167
callbackStyle: 'node'
129168
})
130169
getVersionInfo(): Promise<HotCodePushVersion> { return; }
170+
171+
/**
172+
* Event sent when new release was successfully loaded and ready to be installed.
173+
* @returns {Observable<HotCodePushEventData>}
174+
*/
175+
@Cordova({
176+
eventObservable: true,
177+
event: 'chcp_updateIsReadyToInstall'
178+
})
179+
onUpdateIsReadyToInstall(): Observable<HotCodePushEventData> { return; }
180+
181+
/**
182+
* Event sent when plugin couldn't load update from the server. Error details are attached to the event.
183+
* @returns {Observable<HotCodePushEventData>}
184+
*/
185+
@Cordova({
186+
eventObservable: true,
187+
event: 'chcp_updateLoadFailed'
188+
})
189+
onUpdateLoadFailed(): Observable<HotCodePushEventData> { return; }
190+
191+
/**
192+
* Event sent when we successfully loaded application config from the server, but there is nothing new is available.
193+
* @returns {Observable<HotCodePushEventData>}
194+
*/
195+
@Cordova({
196+
eventObservable: true,
197+
event: 'chcp_nothingToUpdate'
198+
})
199+
onNothingToUpdate(): Observable<HotCodePushEventData> { return; }
200+
201+
/**
202+
* Event sent when an update is about to be installed.
203+
* @returns {Observable<HotCodePushEventData>}
204+
*/
205+
@Cordova({
206+
eventObservable: true,
207+
event: 'chcp_beforeInstall'
208+
})
209+
onBeforeInstall(): Observable<HotCodePushEventData> { return; }
210+
211+
/**
212+
* Event sent when update was successfully installed.
213+
* @returns {Observable<HotCodePushEventData>}
214+
*/
215+
@Cordova({
216+
eventObservable: true,
217+
event: 'chcp_updateInstalled'
218+
})
219+
onUpdateInstalled(): Observable<HotCodePushEventData> { return; }
220+
221+
/**
222+
* Event sent when update installation failed. Error details are attached to the event.
223+
* @returns {Observable<HotCodePushEventData>}
224+
*/
225+
@Cordova({
226+
eventObservable: true,
227+
event: 'chcp_updateInstallFailed'
228+
})
229+
onUpdateInstallFailed(): Observable<HotCodePushEventData> { return; }
230+
231+
/**
232+
* Event sent when there is nothing to install. Probably, nothing was loaded before that.
233+
* @returns {Observable<HotCodePushEventData>}
234+
*/
235+
@Cordova({
236+
eventObservable: true,
237+
event: 'chcp_nothingToInstall'
238+
})
239+
onNothingToInstall(): Observable<HotCodePushEventData> { return; }
240+
241+
/**
242+
* Event sent when plugin is about to start installing bundle content on the external storage.
243+
* @returns {Observable<HotCodePushEventData>}
244+
*/
245+
@Cordova({
246+
eventObservable: true,
247+
event: 'chcp_beforeAssetsInstalledOnExternalStorage'
248+
})
249+
onBeforeAssetsInstalledOnExternalStorage(): Observable<HotCodePushEventData> { return; }
250+
251+
/**
252+
* Event sent when plugin successfully copied web project files from bundle on the external storage. Most likely you will use it for debug purpose only. Or even never.
253+
* @returns {Observable<HotCodePushEventData>}
254+
*/
255+
@Cordova({
256+
eventObservable: true,
257+
event: 'chcp_assetsInstalledOnExternalStorage'
258+
})
259+
onAssetsInstalledOnExternalStorage(): Observable<HotCodePushEventData> { return; }
260+
261+
/**
262+
* Event sent when plugin couldn't copy files from bundle on the external storage. If this happens - plugin won't work. Can occur when there is not enough free space on the device.
263+
* @returns {Observable<HotCodePushEventData>}
264+
*/
265+
@Cordova({
266+
eventObservable: true,
267+
event: 'chcp_assetsInstallationError'
268+
})
269+
onAssetsInstallationError(): Observable<HotCodePushEventData> { return; }
131270
}

0 commit comments

Comments
 (0)