From f736da8ce7a987a184a31d898db192c1866655f3 Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Fri, 7 Jul 2017 19:13:45 -0400 Subject: [PATCH] feat(email-composer): update plugin to latest version and use original plugin (#1771) * change source and document interface * document addAlias example * feat(email-composer): add requestPermission and hasPermission methods * refactor(): use getPlugin() instead of referencing cordova --- .../plugins/email-composer/index.ts | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/src/@ionic-native/plugins/email-composer/index.ts b/src/@ionic-native/plugins/email-composer/index.ts index 1deac3f72b..ad148fd144 100644 --- a/src/@ionic-native/plugins/email-composer/index.ts +++ b/src/@ionic-native/plugins/email-composer/index.ts @@ -1,28 +1,46 @@ import { Injectable } from '@angular/core'; import { Cordova, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core'; -interface Cordova { - plugins: CordovaPlugins & { email: any }; -} - -declare const cordova: Cordova; - export interface EmailComposerOptions { + /** + * App to send the email with + */ app?: string; + /** + * Email address(es) for To field + */ to?: string | Array; + /** + * Email address(es) for CC field + */ cc?: string | Array; + /** + * Email address(es) for BCC field + */ bcc?: string | Array; - attachments?: Array; + /** + * File paths or base64 data streams + */ + attachments?: string[]; + /** + * Subject of the email + */ subject?: string; + /** + * Email body (for HTML, set isHtml to true) + */ body?: string; + /** + * Indicates if the body is HTML or plain text + */ isHtml?: boolean; } @@ -67,16 +85,27 @@ export interface EmailComposerOptions { * * // Send a text message using default options * this.emailComposer.open(email); + * ``` * + * You can also assign aliases to email apps + * ```ts + * // add alias + * this.email.addAlias('gmail', 'com.google.android.gm'); + * + * // then use alias when sending email + * this.email.open({ + * app: 'gmail', + * ... + * }); * ``` * @interfaces * EmailComposerOptions */ @Plugin({ pluginName: 'EmailComposer', - plugin: 'cordova-plugin-email', + plugin: 'cordova-plugin-email-composer', pluginRef: 'cordova.plugins.email', - repo: 'https://github.com/hypery2k/cordova-email-plugin', + repo: 'https://github.com/katzer/cordova-plugin-email-composer', platforms: ['Amazon Fire OS', 'Android', 'Browser', 'iOS', 'Windows'] }) @Injectable() @@ -92,7 +121,7 @@ export class EmailComposer extends IonicNativePlugin { isAvailable(app?: string): Promise { return new Promise((resolve, reject) => { if (app) { - cordova.plugins.email.isAvailable(app, (isAvailable: boolean) => { + EmailComposer.getPlugin().isAvailable(app, (isAvailable: boolean) => { if (isAvailable) { resolve(); } else { @@ -100,7 +129,7 @@ export class EmailComposer extends IonicNativePlugin { } }); } else { - cordova.plugins.email.isAvailable((isAvailable: boolean) => { + EmailComposer.getPlugin().isAvailable((isAvailable: boolean) => { if (isAvailable) { resolve(); } else { @@ -111,6 +140,26 @@ export class EmailComposer extends IonicNativePlugin { }); } + /** + * Request permission to access email accounts information + * @return {Promise} returns a promise that resolves with a boolean that indicates if the permission was granted + */ + @Cordova({ + successIndex: 0, + errorIndex: 2 + }) + requestPermission(): Promise { return; } + + /** + * Checks if the app has a permission to access email accounts information + * @return {Promise} returns a promise that resolves with a boolean that indicates if the permission was granted + */ + @Cordova({ + successIndex: 0, + errorIndex: 2 + }) + hasPermission(): Promise { return; } + /** * Adds a new mail app alias. *