@esslassi/electron-printer 0.0.8 → 0.0.9
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/lib/electronPrinter.js +17 -18
- package/lib/native.d.ts +2 -0
- package/lib/native.js +12 -0
- package/package.json +10 -3
- package/test.js +0 -120
package/lib/electronPrinter.js
CHANGED
|
@@ -19,50 +19,49 @@ exports.printFileAsync = printFileAsync;
|
|
|
19
19
|
exports.getJobAsync = getJobAsync;
|
|
20
20
|
exports.getPrintersAsync = getPrintersAsync;
|
|
21
21
|
exports.getPrinterAsync = getPrinterAsync;
|
|
22
|
-
const
|
|
23
|
-
const native = require(path_1.default.join(__dirname, '../build/Release/electron_printer.node'));
|
|
22
|
+
const native_1 = __importDefault(require("./native"));
|
|
24
23
|
/* ===========================
|
|
25
24
|
DIRECT NATIVE EXPORTS
|
|
26
25
|
=========================== */
|
|
27
26
|
function getPrinters() {
|
|
28
|
-
return
|
|
27
|
+
return native_1.default.getPrinters();
|
|
29
28
|
}
|
|
30
29
|
function getPrinter(printerName) {
|
|
31
|
-
return
|
|
30
|
+
return native_1.default.getPrinter(printerName);
|
|
32
31
|
}
|
|
33
32
|
function getPrinterDriverOptions(printerName) {
|
|
34
|
-
return
|
|
33
|
+
return native_1.default.getPrinterDriverOptions(printerName);
|
|
35
34
|
}
|
|
36
35
|
function getSelectedPaperSize(printerName) {
|
|
37
|
-
return
|
|
36
|
+
return native_1.default.getSelectedPaperSize(printerName);
|
|
38
37
|
}
|
|
39
38
|
function getDefaultPrinterName() {
|
|
40
|
-
return
|
|
39
|
+
return native_1.default.getDefaultPrinterName();
|
|
41
40
|
}
|
|
42
41
|
function printDirect(options) {
|
|
43
|
-
|
|
42
|
+
native_1.default.printDirect(options);
|
|
44
43
|
}
|
|
45
44
|
function printFile(options) {
|
|
46
|
-
|
|
45
|
+
native_1.default.printFile(options);
|
|
47
46
|
}
|
|
48
47
|
function getSupportedPrintFormats() {
|
|
49
|
-
return
|
|
48
|
+
return native_1.default.getSupportedPrintFormats();
|
|
50
49
|
}
|
|
51
50
|
function getJob(printerName, jobId) {
|
|
52
|
-
return
|
|
51
|
+
return native_1.default.getJob(printerName, jobId);
|
|
53
52
|
}
|
|
54
53
|
function setJob(printerName, jobId, command) {
|
|
55
|
-
|
|
54
|
+
native_1.default.setJob(printerName, jobId, command);
|
|
56
55
|
}
|
|
57
56
|
function getSupportedJobCommands() {
|
|
58
|
-
return
|
|
57
|
+
return native_1.default.getSupportedJobCommands();
|
|
59
58
|
}
|
|
60
59
|
/* ==================================================
|
|
61
60
|
PROMISE WRAPPERS (Async/Await Friendly)
|
|
62
61
|
================================================== */
|
|
63
62
|
function printDirectAsync(options) {
|
|
64
63
|
return new Promise((resolve, reject) => {
|
|
65
|
-
|
|
64
|
+
native_1.default.printDirect({
|
|
66
65
|
...options,
|
|
67
66
|
success: (jobId) => resolve(jobId),
|
|
68
67
|
error: (err) => reject(err)
|
|
@@ -71,7 +70,7 @@ function printDirectAsync(options) {
|
|
|
71
70
|
}
|
|
72
71
|
function printFileAsync(options) {
|
|
73
72
|
return new Promise((resolve, reject) => {
|
|
74
|
-
|
|
73
|
+
native_1.default.printFile({
|
|
75
74
|
...options,
|
|
76
75
|
success: (jobId) => resolve(jobId),
|
|
77
76
|
error: (err) => reject(err)
|
|
@@ -79,11 +78,11 @@ function printFileAsync(options) {
|
|
|
79
78
|
});
|
|
80
79
|
}
|
|
81
80
|
function getJobAsync(printerName, jobId) {
|
|
82
|
-
return Promise.resolve(
|
|
81
|
+
return Promise.resolve(native_1.default.getJob(printerName, jobId));
|
|
83
82
|
}
|
|
84
83
|
function getPrintersAsync() {
|
|
85
|
-
return Promise.resolve(
|
|
84
|
+
return Promise.resolve(native_1.default.getPrinters());
|
|
86
85
|
}
|
|
87
86
|
function getPrinterAsync(printerName) {
|
|
88
|
-
return Promise.resolve(
|
|
87
|
+
return Promise.resolve(native_1.default.getPrinter(printerName));
|
|
89
88
|
}
|
package/lib/native.d.ts
ADDED
package/lib/native.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
// Support Electron + Webpack + normal Node
|
|
8
|
+
const req = typeof global.__non_webpack_require__ === 'function'
|
|
9
|
+
? global.__non_webpack_require__
|
|
10
|
+
: require;
|
|
11
|
+
const native = req('node-gyp-build')(path_1.default.join(__dirname, '..'));
|
|
12
|
+
exports.default = native;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esslassi/electron-printer",
|
|
3
3
|
"description": "Node.js and Electron bindings",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
6
7
|
"private": false,
|
|
7
8
|
"scripts": {
|
|
8
9
|
"install": "node-gyp rebuild",
|
|
@@ -36,11 +37,17 @@
|
|
|
36
37
|
},
|
|
37
38
|
"license": "MIT",
|
|
38
39
|
"gypfile": true,
|
|
40
|
+
"files": [
|
|
41
|
+
"lib",
|
|
42
|
+
"prebuilds",
|
|
43
|
+
"binding.gyp",
|
|
44
|
+
"src"
|
|
45
|
+
],
|
|
39
46
|
"dependencies": {
|
|
40
|
-
"bindings": "1.5.0",
|
|
41
47
|
"dotenv": "17.2.3",
|
|
42
48
|
"node-addon-api": "8.5.0",
|
|
43
|
-
"node-gyp": "12.1.0"
|
|
49
|
+
"node-gyp": "12.1.0",
|
|
50
|
+
"node-gyp-build": "^4.8.4"
|
|
44
51
|
},
|
|
45
52
|
"devDependencies": {
|
|
46
53
|
"@semantic-release/changelog": "6.0.3",
|
package/test.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
const printer = require('./lib');
|
|
2
|
-
|
|
3
|
-
async function run() {
|
|
4
|
-
console.log("===== TEST START =====");
|
|
5
|
-
|
|
6
|
-
// -------------------------------------------------
|
|
7
|
-
// 1️⃣ Get printers (sync)
|
|
8
|
-
// -------------------------------------------------
|
|
9
|
-
const printers = printer.getPrinters();
|
|
10
|
-
console.log("Printers:", printers);
|
|
11
|
-
|
|
12
|
-
if (!printers.length) {
|
|
13
|
-
console.log("No printers found. Exiting.");
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const defaultPrinter = printer.getDefaultPrinterName();
|
|
18
|
-
console.log("Default printer:", defaultPrinter);
|
|
19
|
-
|
|
20
|
-
const selectedPrinter = defaultPrinter || printers[0].name;
|
|
21
|
-
console.log("Using printer:", selectedPrinter);
|
|
22
|
-
|
|
23
|
-
// -------------------------------------------------
|
|
24
|
-
// 2️⃣ Get single printer
|
|
25
|
-
// -------------------------------------------------
|
|
26
|
-
const printerDetails = printer.getPrinter(selectedPrinter);
|
|
27
|
-
console.log("Printer details:", printerDetails);
|
|
28
|
-
|
|
29
|
-
// -------------------------------------------------
|
|
30
|
-
// 3️⃣ Driver options
|
|
31
|
-
// -------------------------------------------------
|
|
32
|
-
const driverOptions = printer.getPrinterDriverOptions(selectedPrinter);
|
|
33
|
-
console.log("Driver options:", driverOptions);
|
|
34
|
-
|
|
35
|
-
// -------------------------------------------------
|
|
36
|
-
// 4️⃣ Paper size
|
|
37
|
-
// -------------------------------------------------
|
|
38
|
-
const paper = printer.getSelectedPaperSize(selectedPrinter);
|
|
39
|
-
console.log("Selected paper size:", paper);
|
|
40
|
-
|
|
41
|
-
// -------------------------------------------------
|
|
42
|
-
// 5️⃣ Supported formats
|
|
43
|
-
// -------------------------------------------------
|
|
44
|
-
console.log("Supported formats:", printer.getSupportedPrintFormats());
|
|
45
|
-
|
|
46
|
-
// -------------------------------------------------
|
|
47
|
-
// 6️⃣ Supported job commands
|
|
48
|
-
// -------------------------------------------------
|
|
49
|
-
console.log("Supported job commands:", printer.getSupportedJobCommands());
|
|
50
|
-
|
|
51
|
-
// -------------------------------------------------
|
|
52
|
-
// 7️⃣ printDirect (callback version)
|
|
53
|
-
// -------------------------------------------------
|
|
54
|
-
printer.printDirect({
|
|
55
|
-
data: "TEST PRINT FROM CALLBACK\n\n",
|
|
56
|
-
printer: selectedPrinter,
|
|
57
|
-
type: "RAW",
|
|
58
|
-
success: (jobId) => {
|
|
59
|
-
console.log("printDirect success jobId:", jobId);
|
|
60
|
-
|
|
61
|
-
const job = printer.getJob(selectedPrinter, parseInt(jobId));
|
|
62
|
-
console.log("Job details (sync):", job);
|
|
63
|
-
|
|
64
|
-
// Try cancel test (optional)
|
|
65
|
-
// printer.setJob(selectedPrinter, parseInt(jobId), "CANCEL");
|
|
66
|
-
},
|
|
67
|
-
error: (err) => {
|
|
68
|
-
console.error("printDirect error:", err);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// -------------------------------------------------
|
|
73
|
-
// 8️⃣ printDirectAsync
|
|
74
|
-
// -------------------------------------------------
|
|
75
|
-
try {
|
|
76
|
-
const jobId = await printer.printDirectAsync({
|
|
77
|
-
data: Buffer.from("TEST PRINT FROM ASYNC\n\n"),
|
|
78
|
-
printer: selectedPrinter,
|
|
79
|
-
type: "RAW"
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
console.log("printDirectAsync jobId:", jobId);
|
|
83
|
-
|
|
84
|
-
const jobAsync = await printer.getJobAsync(selectedPrinter, parseInt(jobId));
|
|
85
|
-
console.log("Job details (async):", jobAsync);
|
|
86
|
-
|
|
87
|
-
} catch (err) {
|
|
88
|
-
console.error("printDirectAsync error:", err);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// -------------------------------------------------
|
|
92
|
-
// 9️⃣ printFileAsync
|
|
93
|
-
// -------------------------------------------------
|
|
94
|
-
try {
|
|
95
|
-
const jobId = await printer.printFileAsync({
|
|
96
|
-
filename: "./sample.txt", // make sure this exists
|
|
97
|
-
printer: selectedPrinter
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
console.log("printFileAsync jobId:", jobId);
|
|
101
|
-
} catch (err) {
|
|
102
|
-
console.error("printFileAsync error:", err);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// -------------------------------------------------
|
|
106
|
-
// 🔟 getPrintersAsync
|
|
107
|
-
// -------------------------------------------------
|
|
108
|
-
const printersAsync = await printer.getPrintersAsync();
|
|
109
|
-
console.log("Printers (async):", printersAsync);
|
|
110
|
-
|
|
111
|
-
// -------------------------------------------------
|
|
112
|
-
// 11️⃣ getPrinterAsync
|
|
113
|
-
// -------------------------------------------------
|
|
114
|
-
const singlePrinterAsync = await printer.getPrinterAsync(selectedPrinter);
|
|
115
|
-
console.log("Single printer (async):", singlePrinterAsync);
|
|
116
|
-
|
|
117
|
-
console.log("===== TEST END =====");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
run().catch(console.error);
|