code-poltergeist-system-monitor 1.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of code-poltergeist-system-monitor might be problematic. Click here for more details.

Files changed (33) hide show
  1. package/index.js +74 -0
  2. package/package.json +21 -0
  3. package/te/node_modules/.package-lock.json +44 -0
  4. package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
  5. package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
  6. package/te/node_modules/systeminformation/LICENSE +20 -0
  7. package/te/node_modules/systeminformation/README.md +1116 -0
  8. package/te/node_modules/systeminformation/lib/audio.js +222 -0
  9. package/te/node_modules/systeminformation/lib/battery.js +311 -0
  10. package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
  11. package/te/node_modules/systeminformation/lib/cli.js +91 -0
  12. package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
  13. package/te/node_modules/systeminformation/lib/docker.js +758 -0
  14. package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
  15. package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
  16. package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
  17. package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
  18. package/te/node_modules/systeminformation/lib/index.js +504 -0
  19. package/te/node_modules/systeminformation/lib/internet.js +237 -0
  20. package/te/node_modules/systeminformation/lib/memory.js +575 -0
  21. package/te/node_modules/systeminformation/lib/network.js +1783 -0
  22. package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
  23. package/te/node_modules/systeminformation/lib/printer.js +210 -0
  24. package/te/node_modules/systeminformation/lib/processes.js +1296 -0
  25. package/te/node_modules/systeminformation/lib/system.js +742 -0
  26. package/te/node_modules/systeminformation/lib/usb.js +279 -0
  27. package/te/node_modules/systeminformation/lib/users.js +363 -0
  28. package/te/node_modules/systeminformation/lib/util.js +1373 -0
  29. package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
  30. package/te/node_modules/systeminformation/lib/wifi.js +834 -0
  31. package/te/node_modules/systeminformation/package.json +99 -0
  32. package/te/package-lock.json +52 -0
  33. package/te/package.json +15 -0
@@ -0,0 +1,222 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // audio.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2024
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 16. audio
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const exec = require('child_process').exec;
17
+ const execSync = require('child_process').execSync;
18
+ const util = require('./util');
19
+
20
+ let _platform = process.platform;
21
+
22
+ const _linux = (_platform === 'linux' || _platform === 'android');
23
+ const _darwin = (_platform === 'darwin');
24
+ const _windows = (_platform === 'win32');
25
+ const _freebsd = (_platform === 'freebsd');
26
+ const _openbsd = (_platform === 'openbsd');
27
+ const _netbsd = (_platform === 'netbsd');
28
+ const _sunos = (_platform === 'sunos');
29
+
30
+ function parseAudioType(str, input, output) {
31
+ str = str.toLowerCase();
32
+ let result = '';
33
+
34
+ if (str.indexOf('input') >= 0) { result = 'Microphone'; }
35
+ if (str.indexOf('display audio') >= 0) { result = 'Speaker'; }
36
+ if (str.indexOf('speak') >= 0) { result = 'Speaker'; }
37
+ if (str.indexOf('laut') >= 0) { result = 'Speaker'; }
38
+ if (str.indexOf('loud') >= 0) { result = 'Speaker'; }
39
+ if (str.indexOf('head') >= 0) { result = 'Headset'; }
40
+ if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
41
+ if (str.indexOf('mikr') >= 0) { result = 'Microphone'; }
42
+ if (str.indexOf('phone') >= 0) { result = 'Phone'; }
43
+ if (str.indexOf('controll') >= 0) { result = 'Controller'; }
44
+ if (str.indexOf('line o') >= 0) { result = 'Line Out'; }
45
+ if (str.indexOf('digital o') >= 0) { result = 'Digital Out'; }
46
+ if (str.indexOf('smart sound technology') >= 0) { result = 'Digital Signal Processor'; }
47
+ if (str.indexOf('high definition audio') >= 0) { result = 'Sound Driver'; }
48
+
49
+ if (!result && output) {
50
+ result = 'Speaker';
51
+ } else if (!result && input) {
52
+ result = 'Microphone';
53
+ }
54
+ return result;
55
+ }
56
+
57
+
58
+ function getLinuxAudioPci() {
59
+ let cmd = 'lspci -v 2>/dev/null';
60
+ let result = [];
61
+ try {
62
+ const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n');
63
+ parts.forEach(element => {
64
+ const lines = element.split('\n');
65
+ if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
66
+ const audio = {};
67
+ audio.slotId = lines[0].split(' ')[0];
68
+ audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
69
+ result.push(audio);
70
+ }
71
+ });
72
+ return result;
73
+ } catch (e) {
74
+ return result;
75
+ }
76
+ }
77
+
78
+ function parseLinuxAudioPciMM(lines, audioPCI) {
79
+ const result = {};
80
+ const slotId = util.getValue(lines, 'Slot');
81
+
82
+ const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
83
+
84
+ result.id = slotId;
85
+ result.name = util.getValue(lines, 'SDevice');
86
+ result.manufacturer = util.getValue(lines, 'SVendor');
87
+ result.revision = util.getValue(lines, 'Rev');
88
+ result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : '';
89
+ result.default = null;
90
+ result.channel = 'PCIe';
91
+ result.type = parseAudioType(result.name, null, null);
92
+ result.in = null;
93
+ result.out = null;
94
+ result.status = 'online';
95
+
96
+ return result;
97
+ }
98
+
99
+ function parseDarwinChannel(str) {
100
+ let result = '';
101
+
102
+ if (str.indexOf('builtin') >= 0) { result = 'Built-In'; }
103
+ if (str.indexOf('extern') >= 0) { result = 'Audio-Jack'; }
104
+ if (str.indexOf('hdmi') >= 0) { result = 'HDMI'; }
105
+ if (str.indexOf('displayport') >= 0) { result = 'Display-Port'; }
106
+ if (str.indexOf('usb') >= 0) { result = 'USB'; }
107
+ if (str.indexOf('pci') >= 0) { result = 'PCIe'; }
108
+
109
+ return result;
110
+ }
111
+
112
+ function parseDarwinAudio(audioObject, id) {
113
+ const result = {};
114
+ const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
115
+
116
+ result.id = id;
117
+ result.name = audioObject._name;
118
+ result.manufacturer = audioObject.coreaudio_device_manufacturer;
119
+ result.revision = null;
120
+ result.driver = null;
121
+ result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
122
+ result.channel = parseDarwinChannel(channelStr);
123
+ result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || ''));
124
+ result.in = !!(audioObject.coreaudio_device_input || '');
125
+ result.out = !!(audioObject.coreaudio_device_output || '');
126
+ result.status = 'online';
127
+
128
+ return result;
129
+ }
130
+
131
+ function parseWindowsAudio(lines) {
132
+ const result = {};
133
+ const status = util.getValue(lines, 'StatusInfo', ':');
134
+
135
+ result.id = util.getValue(lines, 'DeviceID', ':'); // PNPDeviceID??
136
+ result.name = util.getValue(lines, 'name', ':');
137
+ result.manufacturer = util.getValue(lines, 'manufacturer', ':');
138
+ result.revision = null;
139
+ result.driver = null;
140
+ result.default = null;
141
+ result.channel = null;
142
+ result.type = parseAudioType(result.name, null, null);
143
+ result.in = null;
144
+ result.out = null;
145
+ result.status = status;
146
+
147
+ return result;
148
+ }
149
+
150
+ function audio(callback) {
151
+
152
+ return new Promise((resolve) => {
153
+ process.nextTick(() => {
154
+ let result = [];
155
+ if (_linux || _freebsd || _openbsd || _netbsd) {
156
+ let cmd = 'lspci -vmm 2>/dev/null';
157
+ exec(cmd, function (error, stdout) {
158
+ // PCI
159
+ if (!error) {
160
+ const audioPCI = getLinuxAudioPci();
161
+ const parts = stdout.toString().split('\n\n');
162
+ parts.forEach(element => {
163
+ const lines = element.split('\n');
164
+ if (util.getValue(lines, 'class', ':', true).toLowerCase().indexOf('audio') >= 0) {
165
+ const audio = parseLinuxAudioPciMM(lines, audioPCI);
166
+ result.push(audio);
167
+ }
168
+ });
169
+ }
170
+ if (callback) {
171
+ callback(result);
172
+ }
173
+ resolve(result);
174
+ });
175
+ }
176
+ if (_darwin) {
177
+ let cmd = 'system_profiler SPAudioDataType -json';
178
+ exec(cmd, function (error, stdout) {
179
+ if (!error) {
180
+ try {
181
+ const outObj = JSON.parse(stdout.toString());
182
+ if (outObj.SPAudioDataType && outObj.SPAudioDataType.length && outObj.SPAudioDataType[0] && outObj.SPAudioDataType[0]['_items'] && outObj.SPAudioDataType[0]['_items'].length) {
183
+ for (let i = 0; i < outObj.SPAudioDataType[0]['_items'].length; i++) {
184
+ const audio = parseDarwinAudio(outObj.SPAudioDataType[0]['_items'][i], i);
185
+ result.push(audio);
186
+ }
187
+ }
188
+ } catch (e) {
189
+ util.noop();
190
+ }
191
+ }
192
+ if (callback) {
193
+ callback(result);
194
+ }
195
+ resolve(result);
196
+ });
197
+ }
198
+ if (_windows) {
199
+ util.powerShell('Get-CimInstance Win32_SoundDevice | select DeviceID,StatusInfo,Name,Manufacturer | fl').then((stdout, error) => {
200
+ if (!error) {
201
+ const parts = stdout.toString().split(/\n\s*\n/);
202
+ parts.forEach(element => {
203
+ const lines = element.split('\n');
204
+ if (util.getValue(lines, 'name', ':')) {
205
+ result.push(parseWindowsAudio(lines));
206
+ }
207
+ });
208
+ }
209
+ if (callback) {
210
+ callback(result);
211
+ }
212
+ resolve(result);
213
+ });
214
+ }
215
+ if (_sunos) {
216
+ resolve(null);
217
+ }
218
+ });
219
+ });
220
+ }
221
+
222
+ exports.audio = audio;
@@ -0,0 +1,311 @@
1
+ 'use strict';
2
+ // @ts-check;
3
+ // ==================================================================================
4
+ // battery.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2024
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 6. Battery
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const exec = require('child_process').exec;
17
+ const fs = require('fs');
18
+ const util = require('./util');
19
+
20
+ let _platform = process.platform;
21
+
22
+ const _linux = (_platform === 'linux' || _platform === 'android');
23
+ const _darwin = (_platform === 'darwin');
24
+ const _windows = (_platform === 'win32');
25
+ const _freebsd = (_platform === 'freebsd');
26
+ const _openbsd = (_platform === 'openbsd');
27
+ const _netbsd = (_platform === 'netbsd');
28
+ const _sunos = (_platform === 'sunos');
29
+
30
+ function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
31
+ const result = {};
32
+ let status = util.getValue(lines, 'BatteryStatus', ':').trim();
33
+ // 1 = "Discharging"
34
+ // 2 = "On A/C"
35
+ // 3 = "Fully Charged"
36
+ // 4 = "Low"
37
+ // 5 = "Critical"
38
+ // 6 = "Charging"
39
+ // 7 = "Charging High"
40
+ // 8 = "Charging Low"
41
+ // 9 = "Charging Critical"
42
+ // 10 = "Undefined"
43
+ // 11 = "Partially Charged"
44
+ if (status >= 0) {
45
+ const statusValue = status ? parseInt(status) : 0;
46
+ result.status = statusValue;
47
+ result.hasBattery = true;
48
+ result.maxCapacity = fullChargeCapacity || parseInt(util.getValue(lines, 'DesignCapacity', ':') || 0);
49
+ result.designedCapacity = parseInt(util.getValue(lines, 'DesignCapacity', ':') || designedCapacity);
50
+ result.voltage = parseInt(util.getValue(lines, 'DesignVoltage', ':') || 0) / 1000.0;
51
+ result.capacityUnit = 'mWh';
52
+ result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', ':') || 0);
53
+ result.currentCapacity = parseInt(result.maxCapacity * result.percent / 100);
54
+ result.isCharging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || ((statusValue !== 3) && (statusValue !== 1) && result.percent < 100);
55
+ result.acConnected = result.isCharging || statusValue === 2;
56
+ result.model = util.getValue(lines, 'DeviceID', ':');
57
+ } else {
58
+ result.status = -1;
59
+ }
60
+
61
+ return result;
62
+ }
63
+
64
+ module.exports = function (callback) {
65
+
66
+ return new Promise((resolve) => {
67
+ process.nextTick(() => {
68
+ let result = {
69
+ hasBattery: false,
70
+ cycleCount: 0,
71
+ isCharging: false,
72
+ designedCapacity: 0,
73
+ maxCapacity: 0,
74
+ currentCapacity: 0,
75
+ voltage: 0,
76
+ capacityUnit: '',
77
+ percent: 0,
78
+ timeRemaining: null,
79
+ acConnected: true,
80
+ type: '',
81
+ model: '',
82
+ manufacturer: '',
83
+ serial: ''
84
+ };
85
+
86
+ if (_linux) {
87
+ let battery_path = '';
88
+ if (fs.existsSync('/sys/class/power_supply/BAT1/uevent')) {
89
+ battery_path = '/sys/class/power_supply/BAT1/';
90
+ } else if (fs.existsSync('/sys/class/power_supply/BAT0/uevent')) {
91
+ battery_path = '/sys/class/power_supply/BAT0/';
92
+ }
93
+
94
+ let acConnected = false;
95
+ let acPath = '';
96
+ if (fs.existsSync('/sys/class/power_supply/AC/online')) {
97
+ acPath = '/sys/class/power_supply/AC/online';
98
+ } else if (fs.existsSync('/sys/class/power_supply/AC0/online')) {
99
+ acPath = '/sys/class/power_supply/AC0/online';
100
+ }
101
+
102
+ if (acPath) {
103
+ const file = fs.readFileSync(acPath);
104
+ acConnected = file.toString().trim() === '1';
105
+ }
106
+
107
+ if (battery_path) {
108
+ fs.readFile(battery_path + 'uevent', function (error, stdout) {
109
+ if (!error) {
110
+ let lines = stdout.toString().split('\n');
111
+
112
+ result.isCharging = (util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging');
113
+ result.acConnected = acConnected || result.isCharging;
114
+ result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
115
+ result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
116
+ result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
117
+ result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0 * (result.voltage || 1));
118
+ const desingedMinVoltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN', '='), 10) / 1000000.0;
119
+ result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '=', true, true), 10) / 1000.0 * (desingedMinVoltage || result.voltage || 1));
120
+ result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 * (result.voltage || 1));
121
+ if (!result.maxCapacity) {
122
+ result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '=', true, true), 10) / 1000.0;
123
+ result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '=', true, true), 10) / 1000.0 | result.maxCapacity;
124
+ result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
125
+ }
126
+ const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
127
+ const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
128
+ const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10);
129
+ const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10);
130
+ const charge = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10);
131
+
132
+ result.percent = parseInt('0' + percent, 10);
133
+ if (result.maxCapacity && result.currentCapacity) {
134
+ result.hasBattery = true;
135
+ if (!percent) {
136
+ result.percent = 100.0 * result.currentCapacity / result.maxCapacity;
137
+ }
138
+ }
139
+ if (result.isCharging) {
140
+ result.hasBattery = true;
141
+ }
142
+ if (energy && power) {
143
+ result.timeRemaining = Math.floor(energy / power * 60);
144
+ } else if (current && charge) {
145
+ result.timeRemaining = Math.floor(charge / current * 60);
146
+ } else if (current && result.currentCapacity) {
147
+ result.timeRemaining = Math.floor(result.currentCapacity / current * 60);
148
+ }
149
+ result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
150
+ result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');
151
+ result.manufacturer = util.getValue(lines, 'POWER_SUPPLY_MANUFACTURER', '=');
152
+ result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
153
+ if (callback) { callback(result); }
154
+ resolve(result);
155
+ } else {
156
+ if (callback) { callback(result); }
157
+ resolve(result);
158
+ }
159
+ });
160
+ } else {
161
+ if (callback) { callback(result); }
162
+ resolve(result);
163
+ }
164
+ }
165
+ if (_freebsd || _openbsd || _netbsd) {
166
+ exec('sysctl -i hw.acpi.battery hw.acpi.acline', function (error, stdout) {
167
+ let lines = stdout.toString().split('\n');
168
+ const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10);
169
+ const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10);
170
+ result.hasBattery = (batteries > 0);
171
+ result.cycleCount = null;
172
+ result.isCharging = util.getValue(lines, 'hw.acpi.acline') !== '1';
173
+ result.acConnected = result.isCharging;
174
+ result.maxCapacity = null;
175
+ result.currentCapacity = null;
176
+ result.capacityUnit = 'unknown';
177
+ result.percent = batteries ? percent : null;
178
+ if (callback) { callback(result); }
179
+ resolve(result);
180
+ });
181
+ }
182
+
183
+ if (_darwin) {
184
+ exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining|Voltage"; pmset -g batt | grep %', function (error, stdout) {
185
+ if (stdout) {
186
+ let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
187
+ result.cycleCount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
188
+ result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
189
+ result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
190
+ result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawmaxcapacity', '='), 10) * (result.voltage || 1));
191
+ result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawcurrentcapacity', '='), 10) * (result.voltage || 1));
192
+ result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1));
193
+ result.manufacturer = 'Apple';
194
+ result.serial = util.getValue(lines, 'BatterySerialNumber', '=');
195
+ let percent = null;
196
+ const line = util.getValue(lines, 'internal', 'Battery');
197
+ let parts = line.split(';');
198
+ if (parts && parts[0]) {
199
+ let parts2 = parts[0].split('\t');
200
+ if (parts2 && parts2[1]) {
201
+ percent = parseFloat(parts2[1].trim().replace(/%/g, ''));
202
+ }
203
+ }
204
+ if (parts && parts[1]) {
205
+ result.isCharging = (parts[1].trim() === 'charging');
206
+ result.acConnected = (parts[1].trim() !== 'discharging');
207
+ } else {
208
+ result.isCharging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes';
209
+ result.acConnected = result.isCharging;
210
+ }
211
+ if (result.maxCapacity && result.currentCapacity) {
212
+ result.hasBattery = true;
213
+ result.type = 'Li-ion';
214
+ result.percent = percent !== null ? percent : Math.round(100.0 * result.currentCapacity / result.maxCapacity);
215
+ if (!result.isCharging) {
216
+ result.timeRemaining = parseInt('0' + util.getValue(lines, 'TimeRemaining', '='), 10);
217
+ }
218
+ }
219
+ }
220
+ if (callback) { callback(result); }
221
+ resolve(result);
222
+ });
223
+ }
224
+ if (_sunos) {
225
+ if (callback) { callback(result); }
226
+ resolve(result);
227
+ }
228
+ if (_windows) {
229
+ try {
230
+ const workload = [];
231
+ workload.push(util.powerShell('Get-CimInstance Win32_Battery | select BatteryStatus, DesignCapacity, DesignVoltage, EstimatedChargeRemaining, DeviceID | fl'));
232
+ workload.push(util.powerShell('(Get-WmiObject -Class BatteryStaticData -Namespace ROOT/WMI).DesignedCapacity'));
233
+ workload.push(util.powerShell('(Get-CimInstance -Class BatteryFullChargedCapacity -Namespace ROOT/WMI).FullChargedCapacity'));
234
+ util.promiseAll(
235
+ workload
236
+ ).then((data) => {
237
+ if (data) {
238
+ let parts = data.results[0].split(/\n\s*\n/);
239
+ let batteries = [];
240
+ const hasValue = value => /\S/.test(value);
241
+ for (let i = 0; i < parts.length; i++) {
242
+ if (hasValue(parts[i]) && (!batteries.length || !hasValue(parts[i - 1]))) {
243
+ batteries.push([]);
244
+ }
245
+ if (hasValue(parts[i])) {
246
+ batteries[batteries.length - 1].push(parts[i]);
247
+ }
248
+ }
249
+ let designCapacities = data.results[1].split('\r\n').filter(e => e);
250
+ let fullChargeCapacities = data.results[2].split('\r\n').filter(e => e);
251
+ if (batteries.length) {
252
+ let first = false;
253
+ let additionalBatteries = [];
254
+ for (let i = 0; i < batteries.length; i++) {
255
+ let lines = batteries[i][0].split('\r\n');
256
+ const designedCapacity = designCapacities && designCapacities.length >= (i + 1) && designCapacities[i] ? util.toInt(designCapacities[i]) : 0;
257
+ const fullChargeCapacity = fullChargeCapacities && fullChargeCapacities.length >= (i + 1) && fullChargeCapacities[i] ? util.toInt(fullChargeCapacities[i]) : 0;
258
+ const parsed = parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity);
259
+ if (!first && parsed.status > 0 && parsed.status !== 10) {
260
+ result.hasBattery = parsed.hasBattery;
261
+ result.maxCapacity = parsed.maxCapacity;
262
+ result.designedCapacity = parsed.designedCapacity;
263
+ result.voltage = parsed.voltage;
264
+ result.capacityUnit = parsed.capacityUnit;
265
+ result.percent = parsed.percent;
266
+ result.currentCapacity = parsed.currentCapacity;
267
+ result.isCharging = parsed.isCharging;
268
+ result.acConnected = parsed.acConnected;
269
+ result.model = parsed.model;
270
+ first = true;
271
+ } else if (parsed.status !== -1) {
272
+ additionalBatteries.push(
273
+ {
274
+ hasBattery: parsed.hasBattery,
275
+ maxCapacity: parsed.maxCapacity,
276
+ designedCapacity: parsed.designedCapacity,
277
+ voltage: parsed.voltage,
278
+ capacityUnit: parsed.capacityUnit,
279
+ percent: parsed.percent,
280
+ currentCapacity: parsed.currentCapacity,
281
+ isCharging: parsed.isCharging,
282
+ timeRemaining: null,
283
+ acConnected: parsed.acConnected,
284
+ model: parsed.model,
285
+ type: '',
286
+ manufacturer: '',
287
+ serial: ''
288
+ }
289
+ );
290
+ }
291
+ }
292
+ if (!first && additionalBatteries.length) {
293
+ result = additionalBatteries[0];
294
+ additionalBatteries.shift();
295
+ }
296
+ if (additionalBatteries.length) {
297
+ result.additionalBatteries = additionalBatteries;
298
+ }
299
+ }
300
+ }
301
+ if (callback) { callback(result); }
302
+ resolve(result);
303
+ });
304
+ } catch (e) {
305
+ if (callback) { callback(result); }
306
+ resolve(result);
307
+ }
308
+ }
309
+ });
310
+ });
311
+ };