From 3d188e1f312cd0429677aa0e57d15aa1508b310e Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 15:33:37 -0500 Subject: [PATCH 1/3] feat(plugin): add app availability plugin --- src/plugins/appavailability.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/plugins/appavailability.ts diff --git a/src/plugins/appavailability.ts b/src/plugins/appavailability.ts new file mode 100644 index 000000000..73f312299 --- /dev/null +++ b/src/plugins/appavailability.ts @@ -0,0 +1,20 @@ +import {Plugin, Cordova} from './plugin'; + +/** + * Requires Cordova plugin: cordova-plugin-appavailability. For more info, please see the [AppAvailability plugin docs](https://github.com/ohh2ahh/AppAvailability). + * + * ``` + * cordova plugin add https://github.com/ohh2ahh/AppAvailability.git + * ``` + * + * @usage + * ```js + * ``` + */ +@Plugin({ + plugin: 'https://github.com/ohh2ahh/AppAvailability.git', + pluginRef: 'appAvailability' +}) +export class AppAvailability { + +} From bc4dcaae535b12a2c2a62f44d7d894c2d99bb598 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 15:35:59 -0500 Subject: [PATCH 2/3] feat(plugin): add functionality to app-availablity plugin --- src/plugins/appavailability.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plugins/appavailability.ts b/src/plugins/appavailability.ts index 73f312299..52cd1510c 100644 --- a/src/plugins/appavailability.ts +++ b/src/plugins/appavailability.ts @@ -17,4 +17,19 @@ import {Plugin, Cordova} from './plugin'; }) export class AppAvailability { + /** + * Checks if an app is available on device + * @param app Package name on android, or URI scheme on iOS + * @returns {Promise} + */ + @Cordova() + static check(app : string) : Promise { + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 + return new Promise((res, rej) => {}); + } + } From 80e7eedcae703ab07f77924493f70a765c433d01 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 15:39:09 -0500 Subject: [PATCH 3/3] docs(plugin): add docs and usage --- src/plugins/appavailability.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plugins/appavailability.ts b/src/plugins/appavailability.ts index 52cd1510c..38480b990 100644 --- a/src/plugins/appavailability.ts +++ b/src/plugins/appavailability.ts @@ -1,6 +1,8 @@ import {Plugin, Cordova} from './plugin'; /** + * This plugin allows you to check if an app is installed on the user's device. It requires an URI Scheme (e.g. twitter://) on iOS or a Package Name (e.g com.twitter.android) on Android. + * * Requires Cordova plugin: cordova-plugin-appavailability. For more info, please see the [AppAvailability plugin docs](https://github.com/ohh2ahh/AppAvailability). * * ``` @@ -9,6 +11,19 @@ import {Plugin, Cordova} from './plugin'; * * @usage * ```js + * var app; + * + * if(device.platform === 'iOS') { + * app = 'twitter://'; + * }else if(device.platform === 'Android'){ + * app = 'com.twitter.android'; + * } + * + * AppAvailability.check(app) + * .then( + * yes => console.log(app + " is available"), + * no => console.log(app + " is NOT available") + * ); * ``` */ @Plugin({