enhanced-printer 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/lib/job-tracker.js +44 -2
  2. package/package.json +1 -1
@@ -6,6 +6,48 @@ exports.getJobInfo = getJobInfo;
6
6
  exports.getAllJobs = getAllJobs;
7
7
  const child_process_1 = require("child_process");
8
8
  const job_name_mapper_1 = require("./job-name-mapper");
9
+ /**
10
+ * Windows print job status flags (bitmask values)
11
+ * See: https://learn.microsoft.com/en-us/windows/win32/printdocs/job-info-2
12
+ */
13
+ const JOB_STATUS_FLAGS = {
14
+ 0x0001: 'Paused',
15
+ 0x0002: 'Error',
16
+ 0x0004: 'Deleting',
17
+ 0x0008: 'Spooling',
18
+ 0x0010: 'Printing',
19
+ 0x0020: 'Offline',
20
+ 0x0040: 'PaperOut',
21
+ 0x0080: 'Printed',
22
+ 0x0100: 'Deleted',
23
+ 0x0200: 'BlockedDeviceQueue',
24
+ 0x0400: 'UserIntervention',
25
+ 0x0800: 'Restart',
26
+ 0x1000: 'Complete',
27
+ 0x2000: 'Retained',
28
+ 0x4000: 'RenderingLocally',
29
+ };
30
+ /**
31
+ * Decodes a numeric job status bitmask into a human-readable string.
32
+ * e.g. 8210 (0x2012) => "Error, Printing, Retained"
33
+ */
34
+ function decodeJobStatus(status) {
35
+ // If it's already a string, return it as-is
36
+ if (typeof status === 'string') {
37
+ return status || 'Unknown';
38
+ }
39
+ const numericStatus = Number(status);
40
+ if (isNaN(numericStatus) || numericStatus === 0) {
41
+ return 'None';
42
+ }
43
+ const flags = [];
44
+ for (const [bit, name] of Object.entries(JOB_STATUS_FLAGS)) {
45
+ if (numericStatus & Number(bit)) {
46
+ flags.push(name);
47
+ }
48
+ }
49
+ return flags.length > 0 ? flags.join(', ') : 'Unknown';
50
+ }
9
51
  /**
10
52
  * Retrieves job ID by document name using PowerShell
11
53
  */
@@ -45,7 +87,7 @@ async function getJobInfoBySystemId(printerName, jobId) {
45
87
  jobName: result.DocumentName || '',
46
88
  customJobName: customName || result.DocumentName || '',
47
89
  printerName: printerName,
48
- status: result.JobStatus || 'Unknown',
90
+ status: decodeJobStatus(result.JobStatus),
49
91
  pages: result.TotalPages || 0,
50
92
  size: result.Size,
51
93
  userName: result.UserName,
@@ -90,7 +132,7 @@ async function getAllJobs(printerName) {
90
132
  jobName: job.DocumentName || '',
91
133
  customJobName: customName || job.DocumentName || '', // Use custom name if available
92
134
  printerName: printerName,
93
- status: job.JobStatus || 'Unknown',
135
+ status: decodeJobStatus(job.JobStatus),
94
136
  pages: job.TotalPages || 0,
95
137
  size: job.Size,
96
138
  userName: job.UserName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enhanced-printer",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Advanced PDF printing library with job tracking, custom page sizes, and tray selection for Node.js and Electron",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",