Skip to content

Commit

Permalink
feat(printer): add check method
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed May 17, 2017
1 parent ecdff8c commit 991f2f0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/@ionic-native/plugins/printer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Injectable } from '@angular/core';
import { Cordova, Plugin, IonicNativePlugin } from '@ionic-native/core';


declare var cordova: any;
import { Cordova, CordovaCheck, Plugin, IonicNativePlugin } from '@ionic-native/core';

export interface PrintOptions {
/**
Expand Down Expand Up @@ -41,6 +38,7 @@ export interface PrintOptions {
*/
bounds?: number[] | any;
}

/**
* @name Printer
* @description Prints documents or HTML rendered content
Expand Down Expand Up @@ -81,8 +79,24 @@ export class Printer extends IonicNativePlugin {
* Checks whether to device is capable of printing.
* @returns {Promise<boolean>}
*/
@Cordova()
isAvailable(): Promise<boolean> { return; }
isAvailable(): Promise<boolean> {
return this.check()
.then((res: any) => Promise.resolve(res.avail));
}

/**
* Checks if the printer service is available (iOS) or if printer services are installed and enabled (Android).
* @return {Promise<any>} returns a promise that resolve with an object indicating whether printing is available, and providing the number of printers available
*/
@CordovaCheck()
check(): Promise<any> {
return new Promise<any>((resolve: Function) => {
Printer.getPlugin()
.check((avail: boolean, count: any) => {
resolve({ avail, count });
});
});
}

/**
* Displays a system interface allowing the user to select an available printer. To speak with a printer directly you need to know the network address by picking them before via `printer.pick`.
Expand Down

0 comments on commit 991f2f0

Please sign in to comment.