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
This commit is contained in:
Ibby Hadeed 2017-07-07 19:13:45 -04:00 committed by GitHub
parent bc6bf6671e
commit d395b42788

View File

@ -1,28 +1,46 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Cordova, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core'; import { Cordova, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core';
interface Cordova {
plugins: CordovaPlugins & { email: any };
}
declare const cordova: Cordova;
export interface EmailComposerOptions { export interface EmailComposerOptions {
/**
* App to send the email with
*/
app?: string; app?: string;
/**
* Email address(es) for To field
*/
to?: string | Array<string>; to?: string | Array<string>;
/**
* Email address(es) for CC field
*/
cc?: string | Array<string>; cc?: string | Array<string>;
/**
* Email address(es) for BCC field
*/
bcc?: string | Array<string>; bcc?: string | Array<string>;
attachments?: Array<any>; /**
* File paths or base64 data streams
*/
attachments?: string[];
/**
* Subject of the email
*/
subject?: string; subject?: string;
/**
* Email body (for HTML, set isHtml to true)
*/
body?: string; body?: string;
/**
* Indicates if the body is HTML or plain text
*/
isHtml?: boolean; isHtml?: boolean;
} }
@ -67,16 +85,27 @@ export interface EmailComposerOptions {
* *
* // Send a text message using default options * // Send a text message using default options
* this.emailComposer.open(email); * 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 * @interfaces
* EmailComposerOptions * EmailComposerOptions
*/ */
@Plugin({ @Plugin({
pluginName: 'EmailComposer', pluginName: 'EmailComposer',
plugin: 'cordova-plugin-email', plugin: 'cordova-plugin-email-composer',
pluginRef: 'cordova.plugins.email', 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'] platforms: ['Amazon Fire OS', 'Android', 'Browser', 'iOS', 'Windows']
}) })
@Injectable() @Injectable()
@ -92,7 +121,7 @@ export class EmailComposer extends IonicNativePlugin {
isAvailable(app?: string): Promise<any> { isAvailable(app?: string): Promise<any> {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
if (app) { if (app) {
cordova.plugins.email.isAvailable(app, (isAvailable: boolean) => { EmailComposer.getPlugin().isAvailable(app, (isAvailable: boolean) => {
if (isAvailable) { if (isAvailable) {
resolve(); resolve();
} else { } else {
@ -100,7 +129,7 @@ export class EmailComposer extends IonicNativePlugin {
} }
}); });
} else { } else {
cordova.plugins.email.isAvailable((isAvailable: boolean) => { EmailComposer.getPlugin().isAvailable((isAvailable: boolean) => {
if (isAvailable) { if (isAvailable) {
resolve(); resolve();
} else { } else {
@ -111,6 +140,26 @@ export class EmailComposer extends IonicNativePlugin {
}); });
} }
/**
* Request permission to access email accounts information
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if the permission was granted
*/
@Cordova({
successIndex: 0,
errorIndex: 2
})
requestPermission(): Promise<boolean> { return; }
/**
* Checks if the app has a permission to access email accounts information
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if the permission was granted
*/
@Cordova({
successIndex: 0,
errorIndex: 2
})
hasPermission(): Promise<boolean> { return; }
/** /**
* Adds a new mail app alias. * Adds a new mail app alias.
* *