@esslassi/electron-printer 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -251
- package/binding.gyp +57 -57
- package/lib/electronPrinter.d.ts +52 -24
- package/lib/electronPrinter.js +81 -30
- package/package.json +1 -1
- package/src/linux_printer.cpp +370 -170
- package/src/linux_printer.h +30 -20
- package/src/mac_printer.cpp +373 -166
- package/src/mac_printer.h +31 -22
- package/src/main.cpp +50 -21
- package/src/print.cpp +353 -272
- package/src/printer_factory.cpp +19 -19
- package/src/printer_factory.h +12 -12
- package/src/printer_interface.h +66 -28
- package/src/windows_printer.cpp +347 -210
- package/src/windows_printer.h +63 -34
- package/test.js +120 -0
package/lib/electronPrinter.d.ts
CHANGED
|
@@ -1,33 +1,61 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type PrintOnSuccessFunction = (jobId: string) => any;
|
|
2
|
+
export type PrintOnErrorFunction = (err: Error) => any;
|
|
3
|
+
export interface PrintDirectOptions {
|
|
3
4
|
data: string | Buffer;
|
|
4
|
-
|
|
5
|
+
printer?: string;
|
|
6
|
+
type?: 'RAW' | 'TEXT' | 'COMMAND' | 'AUTO';
|
|
7
|
+
options?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
success?: PrintOnSuccessFunction;
|
|
11
|
+
error?: PrintOnErrorFunction;
|
|
5
12
|
}
|
|
6
|
-
export interface
|
|
13
|
+
export interface PrintFileOptions {
|
|
14
|
+
filename: string;
|
|
15
|
+
printer?: string;
|
|
16
|
+
success?: PrintOnSuccessFunction;
|
|
17
|
+
error?: PrintOnErrorFunction;
|
|
18
|
+
}
|
|
19
|
+
export interface PrinterDetails {
|
|
7
20
|
name: string;
|
|
8
21
|
isDefault: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
location?: string;
|
|
12
|
-
comment?: string;
|
|
13
|
-
driver?: string;
|
|
14
|
-
port?: string;
|
|
15
|
-
[key: string]: string | undefined;
|
|
22
|
+
options: {
|
|
23
|
+
[key: string]: string;
|
|
16
24
|
};
|
|
17
25
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export interface GetStatusPrinterOptions {
|
|
24
|
-
printerName: string;
|
|
26
|
+
export interface PrinterDriverOptions {
|
|
27
|
+
[key: string]: {
|
|
28
|
+
[key: string]: boolean;
|
|
29
|
+
};
|
|
25
30
|
}
|
|
26
|
-
export
|
|
31
|
+
export type JobStatus = 'PAUSED' | 'PRINTING' | 'PRINTED' | 'CANCELLED' | 'PENDING' | 'ABORTED';
|
|
32
|
+
export type JobCommand = "CANCEL" | "PAUSE" | "RESUME";
|
|
33
|
+
export interface JobDetails {
|
|
34
|
+
id: number;
|
|
27
35
|
name: string;
|
|
28
|
-
|
|
36
|
+
printerName: string;
|
|
37
|
+
user: string;
|
|
38
|
+
format: string;
|
|
39
|
+
priority: number;
|
|
40
|
+
size: number;
|
|
41
|
+
status: JobStatus[];
|
|
42
|
+
completedTime: Date;
|
|
43
|
+
creationTime: Date;
|
|
44
|
+
processingTime: Date;
|
|
29
45
|
}
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
46
|
+
export declare function getPrinters(): PrinterDetails[];
|
|
47
|
+
export declare function getPrinter(printerName: string): PrinterDetails;
|
|
48
|
+
export declare function getPrinterDriverOptions(printerName: string): PrinterDriverOptions;
|
|
49
|
+
export declare function getSelectedPaperSize(printerName: string): string;
|
|
50
|
+
export declare function getDefaultPrinterName(): string | undefined;
|
|
51
|
+
export declare function printDirect(options: PrintDirectOptions): void;
|
|
52
|
+
export declare function printFile(options: PrintFileOptions): void;
|
|
53
|
+
export declare function getSupportedPrintFormats(): string[];
|
|
54
|
+
export declare function getJob(printerName: string, jobId: number): JobDetails;
|
|
55
|
+
export declare function setJob(printerName: string, jobId: number, command: JobCommand): void;
|
|
56
|
+
export declare function getSupportedJobCommands(): string[];
|
|
57
|
+
export declare function printDirectAsync(options: Omit<PrintDirectOptions, 'success' | 'error'>): Promise<string>;
|
|
58
|
+
export declare function printFileAsync(options: Omit<PrintFileOptions, 'success' | 'error'>): Promise<string>;
|
|
59
|
+
export declare function getJobAsync(printerName: string, jobId: number): Promise<JobDetails>;
|
|
60
|
+
export declare function getPrintersAsync(): Promise<PrinterDetails[]>;
|
|
61
|
+
export declare function getPrinterAsync(printerName: string): Promise<PrinterDetails>;
|
package/lib/electronPrinter.js
CHANGED
|
@@ -3,36 +3,87 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.printDirect = printDirect;
|
|
7
|
-
exports.getStatusPrinter = getStatusPrinter;
|
|
8
6
|
exports.getPrinters = getPrinters;
|
|
9
|
-
exports.
|
|
7
|
+
exports.getPrinter = getPrinter;
|
|
8
|
+
exports.getPrinterDriverOptions = getPrinterDriverOptions;
|
|
9
|
+
exports.getSelectedPaperSize = getSelectedPaperSize;
|
|
10
|
+
exports.getDefaultPrinterName = getDefaultPrinterName;
|
|
11
|
+
exports.printDirect = printDirect;
|
|
12
|
+
exports.printFile = printFile;
|
|
13
|
+
exports.getSupportedPrintFormats = getSupportedPrintFormats;
|
|
14
|
+
exports.getJob = getJob;
|
|
15
|
+
exports.setJob = setJob;
|
|
16
|
+
exports.getSupportedJobCommands = getSupportedJobCommands;
|
|
17
|
+
exports.printDirectAsync = printDirectAsync;
|
|
18
|
+
exports.printFileAsync = printFileAsync;
|
|
19
|
+
exports.getJobAsync = getJobAsync;
|
|
20
|
+
exports.getPrintersAsync = getPrintersAsync;
|
|
21
|
+
exports.getPrinterAsync = getPrinterAsync;
|
|
10
22
|
const bindings_1 = __importDefault(require("bindings"));
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
function
|
|
37
|
-
return
|
|
23
|
+
const native = (0, bindings_1.default)('electron_printer');
|
|
24
|
+
/* ===========================
|
|
25
|
+
DIRECT NATIVE EXPORTS
|
|
26
|
+
=========================== */
|
|
27
|
+
function getPrinters() {
|
|
28
|
+
return native.getPrinters();
|
|
29
|
+
}
|
|
30
|
+
function getPrinter(printerName) {
|
|
31
|
+
return native.getPrinter(printerName);
|
|
32
|
+
}
|
|
33
|
+
function getPrinterDriverOptions(printerName) {
|
|
34
|
+
return native.getPrinterDriverOptions(printerName);
|
|
35
|
+
}
|
|
36
|
+
function getSelectedPaperSize(printerName) {
|
|
37
|
+
return native.getSelectedPaperSize(printerName);
|
|
38
|
+
}
|
|
39
|
+
function getDefaultPrinterName() {
|
|
40
|
+
return native.getDefaultPrinterName();
|
|
41
|
+
}
|
|
42
|
+
function printDirect(options) {
|
|
43
|
+
native.printDirect(options);
|
|
44
|
+
}
|
|
45
|
+
function printFile(options) {
|
|
46
|
+
native.printFile(options);
|
|
47
|
+
}
|
|
48
|
+
function getSupportedPrintFormats() {
|
|
49
|
+
return native.getSupportedPrintFormats();
|
|
50
|
+
}
|
|
51
|
+
function getJob(printerName, jobId) {
|
|
52
|
+
return native.getJob(printerName, jobId);
|
|
53
|
+
}
|
|
54
|
+
function setJob(printerName, jobId, command) {
|
|
55
|
+
native.setJob(printerName, jobId, command);
|
|
56
|
+
}
|
|
57
|
+
function getSupportedJobCommands() {
|
|
58
|
+
return native.getSupportedJobCommands();
|
|
59
|
+
}
|
|
60
|
+
/* ==================================================
|
|
61
|
+
PROMISE WRAPPERS (Async/Await Friendly)
|
|
62
|
+
================================================== */
|
|
63
|
+
function printDirectAsync(options) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
native.printDirect({
|
|
66
|
+
...options,
|
|
67
|
+
success: (jobId) => resolve(jobId),
|
|
68
|
+
error: (err) => reject(err)
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function printFileAsync(options) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
native.printFile({
|
|
75
|
+
...options,
|
|
76
|
+
success: (jobId) => resolve(jobId),
|
|
77
|
+
error: (err) => reject(err)
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function getJobAsync(printerName, jobId) {
|
|
82
|
+
return Promise.resolve(native.getJob(printerName, jobId));
|
|
83
|
+
}
|
|
84
|
+
function getPrintersAsync() {
|
|
85
|
+
return Promise.resolve(native.getPrinters());
|
|
86
|
+
}
|
|
87
|
+
function getPrinterAsync(printerName) {
|
|
88
|
+
return Promise.resolve(native.getPrinter(printerName));
|
|
38
89
|
}
|