diff --git a/docs/trademarks.html b/docs/trademarks.html
index 7b5ebcc..abb1b67 100644
--- a/docs/trademarks.html
+++ b/docs/trademarks.html
@@ -46,7 +46,7 @@
- Node.js is a trademark of Joyent Inc.
- Linux is a registered trademark of Linus Torvalds
- - Apple, macOS, OS X are registered trademarks of Apple Inc.
+ - Apple, macOS, OS X, CUPS are registered trademarks of Apple Inc.
- Windows is a registered trademark of Microsoft Corporation
- Intel is a trademark of Intel Corporation
- AMD is a trademark of Advanced Micro Devices Inc.
diff --git a/lib/filesystem.js b/lib/filesystem.js
index a23547d..86846a9 100755
--- a/lib/filesystem.js
+++ b/lib/filesystem.js
@@ -60,7 +60,7 @@ function fsSize(callback) {
const size = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])) * 1024;
const used = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2])) * 1024;
const available = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[4] : line[3])) * 1024;
- const use = parseFloat((100.0 * (used / (used + available)).toFixed(2)).toFixed(2));
+ const use = parseFloat((100.0 * (used / (used + available))).toFixed(2));
const mount = line[line.length - 1];
if (!data.find(el => (el.fs === fs && el.type === fstype))) {
data.push({
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 0e5d206..9b4c1f8 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -705,6 +705,18 @@ export namespace Systeminformation {
RTC: string;
}
+ interface PrinterData {
+ id: number;
+ name: string;
+ model: string;
+ uri: string;
+ uuid: string;
+ local: boolean;
+ status: string;
+ default: boolean;
+ shared: boolean;
+ }
+
// 10. "Get All at once" - functions
interface StaticData {
@@ -783,6 +795,8 @@ export function dockerAll(cb?: (data: any) => any): Promise;
export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any): Promise;
+export function printer(cb?: (data: Systeminformation.PrinterData[]) => any): Promise;
+
export function getStaticData(cb?: (data: Systeminformation.StaticData) => any): Promise;
export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) => any): Promise;
export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise;
diff --git a/lib/index.js b/lib/index.js
index 8f22129..002a3c8 100755
--- a/lib/index.js
+++ b/lib/index.js
@@ -37,6 +37,7 @@ const users = require('./users');
const internet = require('./internet');
const docker = require('./docker');
const vbox = require('./virtualbox');
+const printer = require('./printer');
let _platform = process.platform;
const _windows = (_platform === 'win32');
@@ -453,6 +454,8 @@ exports.dockerAll = docker.dockerAll;
exports.vboxInfo = vbox.vboxInfo;
+exports.printer = printer.printer;
+
exports.getStaticData = getStaticData;
exports.getDynamicData = getDynamicData;
exports.getAllData = getAllData;
diff --git a/lib/printer.js b/lib/printer.js
new file mode 100644
index 0000000..2b723c1
--- /dev/null
+++ b/lib/printer.js
@@ -0,0 +1,193 @@
+'use strict';
+// @ts-check
+// ==================================================================================
+// printers.js
+// ----------------------------------------------------------------------------------
+// Description: System Information - library
+// for Node.js
+// Copyright: (c) 2014 - 2021
+// Author: Sebastian Hildebrandt
+// ----------------------------------------------------------------------------------
+// License: MIT
+// ==================================================================================
+// 15. printers
+// ----------------------------------------------------------------------------------
+
+const exec = require('child_process').exec;
+// const execSync = require('child_process').execSync;
+const util = require('./util');
+// const fs = require('fs');
+
+let _platform = process.platform;
+
+const _linux = (_platform === 'linux');
+const _darwin = (_platform === 'darwin');
+const _windows = (_platform === 'win32');
+const _freebsd = (_platform === 'freebsd');
+const _openbsd = (_platform === 'openbsd');
+const _netbsd = (_platform === 'netbsd');
+const _sunos = (_platform === 'sunos');
+
+const NOT_SUPPORTED = 'not supported';
+
+function parseLinuxCupsHeader(lines) {
+ const result = {}
+ if (lines && lines.length) {
+ if (lines[0].indexOf(' CUPS v') > 0) {
+ const parts = lines[0].split(' CUPS v');
+ result.cupsVersion = parts[1];
+ }
+ }
+ return result;
+}
+
+function parseLinuxCupsPrinter(lines) {
+ const result = {};
+ const printerId = util.getValue(lines, 'PrinterId', ' ');
+ result.id = printerId ? parseInt(printerId, 10) : null;
+ result.name = util.getValue(lines, 'Info', ' ');
+ result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
+ result.uri = util.getValue(lines, 'DeviceURI', ' ');
+ result.uuid = util.getValue(lines, 'UUID', ' ');
+ result.local = util.getValue(lines, 'Location', ' ').toLowerCase().startsWith('local');
+ result.status = util.getValue(lines, 'State', ' ');
+ result.default = null;
+ result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
+
+ return result;
+}
+
+function parseLinuxLpstatPrinter(lines, id) {
+ const result = {};
+ result.id = id
+ result.name = util.getValue(lines, 'Description', ':', true);
+ result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
+ result.uri = null;
+ result.uuid = null
+ result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local');
+ result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')): null
+ result.default = null;
+ result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
+
+ return result;
+}
+
+function parseDarwinPrinters(printerObject, id) {
+ const result = {};
+ const uriParts = printerObject.uri.split('/');
+ result.id = id;
+ result.name = printerObject._name
+ result.model = uriParts.length ? uriParts[uriParts.length - 1] : '';
+ result.uri = printerObject.uri;
+ result.uuid = null
+ result.local = printerObject.printserver === 'local';
+ result.status = printerObject.status;
+ result.default = printerObject.default === 'yes';
+ result.shared = printerObject.shared === 'yes';
+
+ return result;
+}
+
+function parseWindowsPrinters(lines) {
+ return lines;
+}
+
+function printer(callback) {
+
+ return new Promise((resolve, reject) => {
+ process.nextTick(() => {
+ let result = [];
+ if (_linux || _freebsd || _openbsd || _netbsd) {
+ let cmd = 'cat /etc/cups/printers.conf 2>/dev/null'
+ exec(cmd, function (error, stdout) {
+ // printers.conf
+ if (!error) {
+ const parts = stdout.toString().split('