|
1 | 1 | 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'; |
6 | 3 |
|
7 | 4 | export interface PrintOptions {
|
8 | 5 | /**
|
@@ -41,6 +38,7 @@ export interface PrintOptions {
|
41 | 38 | */
|
42 | 39 | bounds?: number[] | any;
|
43 | 40 | }
|
| 41 | + |
44 | 42 | /**
|
45 | 43 | * @name Printer
|
46 | 44 | * @description Prints documents or HTML rendered content
|
@@ -81,8 +79,24 @@ export class Printer extends IonicNativePlugin {
|
81 | 79 | * Checks whether to device is capable of printing.
|
82 | 80 | * @returns {Promise<boolean>}
|
83 | 81 | */
|
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 | + } |
86 | 100 |
|
87 | 101 | /**
|
88 | 102 | * 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