Skip to content

Commit 991f2f0

Browse files
committed
feat(printer): add check method
1 parent ecdff8c commit 991f2f0

File tree

1 file changed

+20
-6
lines changed
  • src/@ionic-native/plugins/printer

1 file changed

+20
-6
lines changed

src/@ionic-native/plugins/printer/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { Cordova, Plugin, IonicNativePlugin } from '@ionic-native/core';
3-
4-
5-
declare var cordova: any;
2+
import { Cordova, CordovaCheck, Plugin, IonicNativePlugin } from '@ionic-native/core';
63

74
export interface PrintOptions {
85
/**
@@ -41,6 +38,7 @@ export interface PrintOptions {
4138
*/
4239
bounds?: number[] | any;
4340
}
41+
4442
/**
4543
* @name Printer
4644
* @description Prints documents or HTML rendered content
@@ -81,8 +79,24 @@ export class Printer extends IonicNativePlugin {
8179
* Checks whether to device is capable of printing.
8280
* @returns {Promise<boolean>}
8381
*/
84-
@Cordova()
85-
isAvailable(): Promise<boolean> { return; }
82+
isAvailable(): Promise<boolean> {
83+
return this.check()
84+
.then((res: any) => Promise.resolve(res.avail));
85+
}
86+
87+
/**
88+
* Checks if the printer service is available (iOS) or if printer services are installed and enabled (Android).
89+
* @return {Promise<any>} returns a promise that resolve with an object indicating whether printing is available, and providing the number of printers available
90+
*/
91+
@CordovaCheck()
92+
check(): Promise<any> {
93+
return new Promise<any>((resolve: Function) => {
94+
Printer.getPlugin()
95+
.check((avail: boolean, count: any) => {
96+
resolve({ avail, count });
97+
});
98+
});
99+
}
86100

87101
/**
88102
* 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`.

0 commit comments

Comments
 (0)