From 21d812225725c0d67b39b8e2860bf5e0e246a367 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sat, 27 Aug 2016 14:43:57 -0400 Subject: [PATCH] feat(file-opener): add file opener support (#497) closes #295 --- src/index.ts | 3 +++ src/plugins/file-opener.ts | 54 ++++++++++++++++++++++++++++++++++++++ src/plugins/plugin.ts | 5 ++++ 3 files changed, 62 insertions(+) create mode 100644 src/plugins/file-opener.ts diff --git a/src/index.ts b/src/index.ts index aac1fd5ae..090a095cc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, diff --git a/src/plugins/file-opener.ts b/src/plugins/file-opener.ts new file mode 100644 index 000000000..b53fb0f08 --- /dev/null +++ b/src/plugins/file-opener.ts @@ -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 {return; } + + /** + * Uninstalls a package + * @param packageId {string} Package ID + */ + @Cordova({ + callbackStyle: 'object', + successName: 'success', + errorName: 'error' + }) + static uninstall(packageId: string): Promise {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 {return; } +} diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index 0ea2ae7fb..305aa57fc 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -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);