feat(file-opener): add file opener support (#497)

closes #295
This commit is contained in:
Ibrahim Hadeed 2016-08-27 14:43:57 -04:00 committed by GitHub
parent 0cf7d6aca1
commit 21d8122257
3 changed files with 62 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import { EstimoteBeacons } from './plugins/estimote-beacons';
import { Facebook } from './plugins/facebook';
import { File } from './plugins/file';
import { FileChooser } from './plugins/file-chooser';
import { FileOpener } from './plugins/file-opener';
import { Transfer } from './plugins/filetransfer';
import { Flashlight } from './plugins/flashlight';
import { Geofence } from './plugins/geofence';
@ -175,6 +176,7 @@ EmailComposer,
EstimoteBeacons,
File,
FileChooser,
FileOpener,
Flashlight,
Geofence,
Globalization,
@ -255,6 +257,7 @@ window['IonicNative'] = {
Facebook: Facebook,
File: File,
FileChooser: FileChooser,
FileOpener: FileOpener,
Flashlight: Flashlight,
Geofence: Geofence,
Geolocation: Geolocation,

View File

@ -0,0 +1,54 @@
import {Plugin, Cordova} from './plugin';
/**
* @name FileOpener
* @description
* This plugin will open a file on your device file system with its default application.
*
* @usage
* ```
* import {FileOpener} from 'ionic-native';
*
*
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-file-opener2',
pluginRef: 'cordova.plugins.fileOpener2',
repo: 'https://github.com/pwlin/cordova-plugin-file-opener2'
})
export class FileOpener {
/**
* Open an file
* @param filePath {string} File Path
* @param fileMIMEType {string} File MIME Type
*/
@Cordova({
callbackStyle: 'object',
successName: 'success',
errorName: 'error'
})
static open(filePath: string, fileMIMEType: string): Promise<any> {return; }
/**
* Uninstalls a package
* @param packageId {string} Package ID
*/
@Cordova({
callbackStyle: 'object',
successName: 'success',
errorName: 'error'
})
static uninstall(packageId: string): Promise<any> {return; }
/**
* Check if an app is already installed
* @param packageId {string} Package ID
*/
@Cordova({
callbackStyle: 'object',
successName: 'success',
errorName: 'error'
})
static appIsInstalled(packageId: string): Promise<any> {return; }
}

View File

@ -56,6 +56,11 @@ function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Func
resolve(result);
}
});
} else if (opts.callbackStyle === 'object' && opts.successName && opts.errorName) {
let obj: any = {};
obj[opts.successName] = resolve;
obj[opts.errorName] = reject;
args.push(obj);
} else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
// If we've specified a success/error index
args.splice(opts.successIndex, 0, resolve);