mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2024-10-07 00:18:08 +08:00
Reimplemented using CordovaInstance.
Fixed wrapInstance signature to match how it is called.
This commit is contained in:
parent
631d7f2d85
commit
9ddde5762d
@ -1,5 +1,4 @@
|
|||||||
import {Plugin, Cordova} from './plugin';
|
import {Plugin, CordovaInstance} from './plugin';
|
||||||
import {Observable} from 'rxjs/Observable';
|
|
||||||
|
|
||||||
declare var FileTransfer;
|
declare var FileTransfer;
|
||||||
|
|
||||||
@ -134,10 +133,10 @@ export class Transfer {
|
|||||||
public static ABORT_ERR: number = 4;
|
public static ABORT_ERR: number = 4;
|
||||||
public static NOT_MODIFIED_ERR: number = 4;
|
public static NOT_MODIFIED_ERR: number = 4;
|
||||||
|
|
||||||
ft: any;
|
private _objectInstance: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ft = new FileTransfer();
|
this._objectInstance = new FileTransfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,14 +148,12 @@ export class Transfer {
|
|||||||
* @param {boolean} trustAllHosts: Optional parameter, defaults to false. If set to true, it accepts all security certificates. This is useful since Android rejects self-signed security certificates. Not recommended for production use. Supported on Android and iOS.
|
* @param {boolean} trustAllHosts: Optional parameter, defaults to false. If set to true, it accepts all security certificates. This is useful since Android rejects self-signed security certificates. Not recommended for production use. Supported on Android and iOS.
|
||||||
* @return Returns a Promise that resolves to a FileUploadResult and rejects with FileTransferError.
|
* @return Returns a Promise that resolves to a FileUploadResult and rejects with FileTransferError.
|
||||||
*/
|
*/
|
||||||
|
@CordovaInstance({
|
||||||
|
successIndex: 2,
|
||||||
|
errorIndex: 3
|
||||||
|
})
|
||||||
upload(fileUrl: string, url: string, options?: FileUploadOptions, trustAllHosts?: boolean): Promise<FileUploadResult> {
|
upload(fileUrl: string, url: string, options?: FileUploadOptions, trustAllHosts?: boolean): Promise<FileUploadResult> {
|
||||||
return new Promise((resolve, reject) => {
|
return;
|
||||||
this.ft.upload(fileUrl, url, (result: FileUploadResult) => {
|
|
||||||
resolve(result);
|
|
||||||
}, (err: FileTransferError) => {
|
|
||||||
reject(err);
|
|
||||||
}, options, trustAllHosts);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,30 +165,30 @@ export class Transfer {
|
|||||||
* @param {object} Optional parameters, currently only supports headers (such as Authorization (Basic Authentication), etc).
|
* @param {object} Optional parameters, currently only supports headers (such as Authorization (Basic Authentication), etc).
|
||||||
* @return Returns a Promise that resolves to a FileEntry object.
|
* @return Returns a Promise that resolves to a FileEntry object.
|
||||||
*/
|
*/
|
||||||
download(source: string, target: string, trustAllHosts?: boolean, options?: { [s: string]: any; }): Promise<any> {
|
@CordovaInstance({
|
||||||
return new Promise((resolve, reject) => {
|
successIndex: 2,
|
||||||
this.ft.download(source, target, (result: any) => {
|
errorIndex: 3
|
||||||
resolve(result);
|
|
||||||
}, (err: FileTransferError) => {
|
|
||||||
reject(err);
|
|
||||||
}, trustAllHosts, options);
|
|
||||||
})
|
})
|
||||||
|
download(source: string, target: string, trustAllHosts?: boolean, options?: { [s: string]: any; }): Promise<any> {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a listener that gets called whenever a new chunk of data is transferred.
|
* Registers a listener that gets called whenever a new chunk of data is transferred.
|
||||||
* @param {function} Listener that takes a progress event.
|
* @param {function} Listener that takes a progress event.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onProgress(listener: (event: ProgressEvent) => any): void {
|
onProgress(listener: (event: ProgressEvent) => any): void {
|
||||||
this.ft.onprocess = listener;
|
this._objectInstance.onprogress = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aborts an in-progress transfer. The onerror callback is passed a FileTransferError
|
* Aborts an in-progress transfer. The onerror callback is passed a FileTransferError
|
||||||
* object which has an error code of FileTransferError.ABORT_ERR.
|
* object which has an error code of FileTransferError.ABORT_ERR.
|
||||||
*/
|
*/
|
||||||
abort(): void {
|
@CordovaInstance({
|
||||||
return this.ft.abort();
|
sync: true
|
||||||
}
|
})
|
||||||
|
abort(): void {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ function callInstance(pluginObj: any, methodName: string, args: any[], opts: any
|
|||||||
return pluginObj._objectInstance[methodName].apply(pluginObj._objectInstance, args);
|
return pluginObj._objectInstance[methodName].apply(pluginObj._objectInstance, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapInstance (pluginObj: any, methodName: string, args: any[], opts: any = {}) {
|
function wrapInstance (pluginObj: any, methodName: string, opts: any = {}) {
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
if (opts.sync) {
|
if (opts.sync) {
|
||||||
return callInstance(pluginObj, methodName, args, opts);
|
return callInstance(pluginObj, methodName, args, opts);
|
||||||
|
Loading…
Reference in New Issue
Block a user