From ce92e6ac8f8e1722ed173ccc0bdf28361549d636 Mon Sep 17 00:00:00 2001 From: Christopher Manouvrier Date: Wed, 6 Apr 2016 22:06:46 +1000 Subject: [PATCH] Refactor isAvailable --- src/plugins/emailcomposer.ts | 39 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/plugins/emailcomposer.ts b/src/plugins/emailcomposer.ts index 076b8cadc..d07e46d49 100644 --- a/src/plugins/emailcomposer.ts +++ b/src/plugins/emailcomposer.ts @@ -1,5 +1,7 @@ import {Plugin, Cordova} from './plugin'; +declare var cordova; + /** * Email object for Opening Email Composer */ @@ -24,6 +26,12 @@ export interface email { * ```ts * import {EmailComposer} from 'ionic-native'; * + * + * EmailComposer.isAvailable().then((available) =>{ + * if(available) { + * //Now we know we can send + * } + * }); * * let email = { * to: 'max@mustermann.de', @@ -53,24 +61,39 @@ export interface email { }) export class EmailComposer { - @Cordova({ - successIndex: 1, - errorIndex: 3 - }) - static isAvailable(app: string, scope: any) : Promise {return} + /** + * Verifies if sending emails is supported on the device. + * + * @param app {string?} An optional app id or uri scheme. Defaults to mailto. + * @param scope {any?} An optional scope for the promise + * @returns {Promise} Resolves promise with boolean whether EmailComposer is available + */ + static isAvailable (app? : string, scope? : any) : Promise { + return new Promise((resolve, reject) => { + cordova.plugins.email.isAvailable(app, resolve, scope); + }); + } + /** + * Adds a new mail app alias. + * + * @param alias {string} The alias name + * @param packageName {string} The package name + */ @Cordova() - static addAlias(alias: string, packageName: string): void {} + static addAlias(alias : string, packageName : string): void {} /** - * Opens Email Composer with email contents + * Displays the email composer pre-filled with data. + * * @param email {email} Email + * @param scope {any?} An optional scope for the promise * @returns {Promise} Resolves promise when the EmailComposer has been opened */ @Cordova({ successIndex: 1, errorIndex: 3 }) - static open(email: email, scope: any) : Promise {return} + static open(email : email, scope? : any) : Promise {return} }