fix(email-composer): Aligned function calls with Cordova plugin
Co-authored-by: ChelloApps<name@example.com> closes: #3220
This commit is contained in:
parent
5223dc7dd5
commit
9057dc2c93
@ -70,9 +70,27 @@ export interface EmailComposerOptions {
|
|||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* this.emailComposer.isAvailable().then((available: boolean) =>{
|
* this.emailComposer.getClients().then((apps: []) => {
|
||||||
|
* // Returns an array of configured email clients for the device
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* this.emailComposer.hasClient().then(app, (isValid: boolean) => {
|
||||||
|
* if (isValid) {
|
||||||
|
* // Now we know we have a valid email client configured
|
||||||
|
* // Not specifying an app will return true if at least one email client is configured
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* this.emailComposer.hasAccount().then((isValid: boolean) => {
|
||||||
|
* if (isValid) {
|
||||||
|
* // Now we know we have a valid email account configured
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* this.emailComposer.isAvailable().then(app, (available: boolean) => {
|
||||||
* if(available) {
|
* if(available) {
|
||||||
* //Now we know we can send
|
* // Now we know we can send an email, calls hasClient and hasAccount
|
||||||
|
* // Not specifying an app will return true if at least one email client is configured
|
||||||
* }
|
* }
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
@ -142,6 +160,68 @@ export class EmailComposer extends IonicNativePlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if an email account is configured on the device.
|
||||||
|
*
|
||||||
|
* @returns {Promise<any>} Resolves if available, rejects if not available
|
||||||
|
*/
|
||||||
|
@CordovaCheck()
|
||||||
|
hasAccount(): Promise<any> {
|
||||||
|
return getPromise<boolean>((resolve) => {
|
||||||
|
EmailComposer.getPlugin().hasAccount((result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if a specific email client is installed on the device.
|
||||||
|
*
|
||||||
|
* @param {string} [app] App id or uri scheme.
|
||||||
|
* @returns {Promise<any>} Resolves if available, rejects if not available
|
||||||
|
*/
|
||||||
|
|
||||||
|
@CordovaCheck()
|
||||||
|
hasClient(app?: string): Promise<any> {
|
||||||
|
return getPromise<boolean>((resolve) => {
|
||||||
|
if (app) {
|
||||||
|
EmailComposer.getPlugin().hasClient(app, (result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
EmailComposer.getPlugin().getClients((apps: string[]) => {
|
||||||
|
resolve(apps.length && apps.length > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of email clients installed on the device.
|
||||||
|
*
|
||||||
|
* @returns {Promise<string[]>} Resolves if available, rejects if not available
|
||||||
|
*/
|
||||||
|
@CordovaCheck()
|
||||||
|
@Cordova({ platforms: ['Android'] })
|
||||||
|
getClients(): Promise<string[]> {
|
||||||
|
return getPromise<string[]>(resolve => {
|
||||||
|
EmailComposer.getPlugin().getClients((apps: any) => {
|
||||||
|
if (Object.prototype.toString.call(apps) === '[object String]') {
|
||||||
|
apps = [apps];
|
||||||
|
}
|
||||||
|
resolve(apps);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies if sending emails is supported on the device.
|
* Verifies if sending emails is supported on the device.
|
||||||
*
|
*
|
||||||
@ -150,24 +230,11 @@ export class EmailComposer extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
isAvailable(app?: string): Promise<any> {
|
isAvailable(app?: string): Promise<any> {
|
||||||
return getPromise<boolean>((resolve, reject) => {
|
return getPromise<boolean>((resolve) => {
|
||||||
if (app) {
|
Promise.all([this.hasAccount, this.hasClient(app)])
|
||||||
EmailComposer.getPlugin().isAvailable(app, (isAvailable: boolean) => {
|
.then((results) => {
|
||||||
if (isAvailable) {
|
return resolve(results.length === 2 && results[0] && results[1]);
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
EmailComposer.getPlugin().isAvailable((isAvailable: boolean) => {
|
|
||||||
if (isAvailable) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user