Skip to content

Commit

Permalink
feat(file-opener): add file opener support (#497)
Browse files Browse the repository at this point in the history
closes #295
  • Loading branch information
ihadeed authored Aug 27, 2016
1 parent 0cf7d6a commit 21d8122
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -175,6 +176,7 @@ EmailComposer,
EstimoteBeacons,
File,
FileChooser,
FileOpener,
Flashlight,
Geofence,
Globalization,
Expand Down Expand Up @@ -255,6 +257,7 @@ window['IonicNative'] = {
Facebook: Facebook,
File: File,
FileChooser: FileChooser,
FileOpener: FileOpener,
Flashlight: Flashlight,
Geofence: Geofence,
Geolocation: Geolocation,
Expand Down
54 changes: 54 additions & 0 deletions src/plugins/file-opener.ts
Original file line number Diff line number Diff line change
@@ -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; }
}
5 changes: 5 additions & 0 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 21d8122

Please sign in to comment.