systeminformation 5.31.16 → 5.31.17

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/cpu.js CHANGED
@@ -2201,12 +2201,27 @@ function getLoad() {
2201
2201
  function currentLoad(callback) {
2202
2202
  return new Promise((resolve) => {
2203
2203
  process.nextTick(() => {
2204
- getLoad().then((result) => {
2205
- if (callback) {
2206
- callback(result);
2207
- }
2208
- resolve(result);
2209
- });
2204
+ if (_current_cpu.ms === 0) {
2205
+ // no baseline yet (first call): prime the counters, then measure over a
2206
+ // short interval instead of returning the average load since boot
2207
+ getLoad().then(() => {
2208
+ setTimeout(() => {
2209
+ getLoad().then((result) => {
2210
+ if (callback) {
2211
+ callback(result);
2212
+ }
2213
+ resolve(result);
2214
+ });
2215
+ }, 500);
2216
+ });
2217
+ } else {
2218
+ getLoad().then((result) => {
2219
+ if (callback) {
2220
+ callback(result);
2221
+ }
2222
+ resolve(result);
2223
+ });
2224
+ }
2210
2225
  });
2211
2226
  });
2212
2227
  }
package/lib/filesystem.js CHANGED
@@ -88,19 +88,23 @@ function fsSize(drive, callback) {
88
88
 
89
89
  function parseDf(lines) {
90
90
  const data = [];
91
+ // filesystem (first column) and mount point (last column) may contain spaces:
92
+ // anchor parsing on the numeric columns in between (blocks, used, available, capacity)
93
+ const dfWithType = /^(.+?)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(?:\d+%|-)\s+(.+)$/;
94
+ const dfNoType = /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(?:\d+%|-)\s+(.+)$/;
95
+ const hasType = _linux || _freebsd || _openbsd || _netbsd;
91
96
  lines.forEach((line) => {
92
97
  if (line !== '') {
93
- line = line.replace(/ +/g, ' ').split(' ');
94
- if (line && (line[0].startsWith('/') || (line[6] && line[6] === '/') || line[0].indexOf('/') > 0 || line[0].indexOf(':') === 1 || (!_darwin && !isLinuxTmpFs(line[1])))) {
95
- const fs = line[0];
96
- const fsType = _linux || _freebsd || _openbsd || _netbsd ? line[1] : getmacOsFsType(line[0]);
97
- const size = parseInt(_linux || _freebsd || _openbsd || _netbsd ? line[2] : line[1], 10) * 1024;
98
- const used = parseInt(_linux || _freebsd || _openbsd || _netbsd ? line[3] : line[2], 10) * 1024;
99
- const available = parseInt(_linux || _freebsd || _openbsd || _netbsd ? line[4] : line[3], 10) * 1024;
98
+ const parts = line.trim().match(hasType ? dfWithType : dfNoType);
99
+ if (parts && (parts[1].startsWith('/') || parts[hasType ? 6 : 5] === '/' || parts[1].indexOf('/') > 0 || parts[1].indexOf(':') === 1 || (!_darwin && !isLinuxTmpFs(parts[2])))) {
100
+ const fs = parts[1];
101
+ const fsType = hasType ? parts[2] : getmacOsFsType(parts[1]);
102
+ const size = parseInt(parts[hasType ? 3 : 2], 10) * 1024;
103
+ const used = parseInt(parts[hasType ? 4 : 3], 10) * 1024;
104
+ const available = parseInt(parts[hasType ? 5 : 4], 10) * 1024;
100
105
  const use = parseFloat((100.0 * (used / (used + available))).toFixed(2));
101
106
  const rw = osMounts && Object.keys(osMounts).length > 0 ? osMounts[fs] || false : null;
102
- line.splice(0, _linux || _freebsd || _openbsd || _netbsd ? 6 : 5);
103
- const mount = line.join(' ');
107
+ const mount = parts[hasType ? 6 : 5];
104
108
  if (!data.find((el) => el.fs === fs && el.type === fsType && el.mount === mount)) {
105
109
  data.push({
106
110
  fs,
@@ -158,9 +162,11 @@ function fsSize(drive, callback) {
158
162
  return line.startsWith('/');
159
163
  })
160
164
  .forEach((line) => {
161
- osMounts[line.split(' ')[0]] = osMounts[line.split(' ')[0]] || false;
165
+ // /proc/mounts escapes spaces as \040
166
+ const fs = line.split(' ')[0].replace(/\\040/g, ' ');
167
+ osMounts[fs] = osMounts[fs] || false;
162
168
  if (line.toLowerCase().indexOf('/snap/') === -1) {
163
- osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('rw,') >= 0 || line.toLowerCase().indexOf(' rw ') >= 0;
169
+ osMounts[fs] = line.toLowerCase().indexOf('rw,') >= 0 || line.toLowerCase().indexOf(' rw ') >= 0;
164
170
  }
165
171
  });
166
172
  } catch {
package/lib/graphics.js CHANGED
@@ -153,7 +153,7 @@ function graphics(callback) {
153
153
  const bus = (item.sppci_bus || '').indexOf('builtin') > -1 ? 'Built-In' : (item.sppci_bus || '').indexOf('pcie') > -1 ? 'PCIe' : '';
154
154
  const vram = (parseInt(item.spdisplays_vram || '', 10) || 0) * ((item.spdisplays_vram || '').indexOf('GB') > -1 ? 1024 : 1);
155
155
  const vramDyn = (parseInt(item.spdisplays_vram_shared || '', 10) || 0) * ((item.spdisplays_vram_shared || '').indexOf('GB') > -1 ? 1024 : 1);
156
- let metalVersion = getMetalVersion(item.spdisplays_metal || item.spdisplays_metalfamily || '');
156
+ const metalVersion = getMetalVersion(item.spdisplays_metal || item.spdisplays_metalfamily || '');
157
157
  res.controllers.push({
158
158
  vendor: getVendorFromModel(item.spdisplays_vendor || '') || item.spdisplays_vendor || '',
159
159
  model: item.sppci_model || '',
@@ -207,7 +207,7 @@ function graphics(callback) {
207
207
  }
208
208
 
209
209
  function parseLinesLinuxControllers(lines) {
210
- let controllers = [];
210
+ const controllers = [];
211
211
  let currentController = {
212
212
  vendor: '',
213
213
  subVendor: '',
@@ -243,9 +243,9 @@ function graphics(callback) {
243
243
  if ('' !== line.trim()) {
244
244
  if (' ' !== line[0] && '\t' !== line[0]) {
245
245
  // first line of new entry
246
- let isExternal = pciIDs.indexOf(line.split(' ')[0]) >= 0;
246
+ const isExternal = pciIDs.indexOf(line.split(' ')[0]) >= 0;
247
247
  let vgapos = line.toLowerCase().indexOf(' vga ');
248
- let _3dcontrollerpos = line.toLowerCase().indexOf('3d controller');
248
+ const _3dcontrollerpos = line.toLowerCase().indexOf('3d controller');
249
249
  if (vgapos !== -1 || _3dcontrollerpos !== -1) {
250
250
  // VGA
251
251
  if (_3dcontrollerpos !== -1 && vgapos === -1) {
@@ -269,8 +269,8 @@ function graphics(callback) {
269
269
  currentController.busAddress = pciIDCandidate;
270
270
  }
271
271
  isGraphicsController = true;
272
- let endpos = line.search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/);
273
- let parts = line.substr(vgapos, endpos - vgapos).split(':');
272
+ const endpos = line.search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/);
273
+ const parts = line.substr(vgapos, endpos - vgapos).split(':');
274
274
  currentController.busAddress = line.substr(0, vgapos).trim();
275
275
  if (parts.length > 1) {
276
276
  parts[1] = parts[1].trim();
@@ -332,7 +332,7 @@ function graphics(callback) {
332
332
  }
333
333
  if (isGraphicsController) {
334
334
  // within VGA details
335
- let parts = line.split(':');
335
+ const parts = line.split(':');
336
336
  if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) {
337
337
  currentController.bus = 'Onboard';
338
338
  }
@@ -341,9 +341,13 @@ function graphics(callback) {
341
341
  if (sizeMatch) {
342
342
  let vram = parseInt(sizeMatch[1], 10);
343
343
  const unit = (sizeMatch[2] || '').toUpperCase();
344
- if (unit === 'G') { vram *= 1024; }
345
- else if (unit === 'K') { vram = Math.round(vram / 1024); }
346
- else if (unit === '') { vram = Math.round(vram / 1024 / 1024); } // bytes
344
+ if (unit === 'G') {
345
+ vram *= 1024;
346
+ } else if (unit === 'K') {
347
+ vram = Math.round(vram / 1024);
348
+ } else if (unit === '') {
349
+ vram = Math.round(vram / 1024 / 1024);
350
+ } // bytes
347
351
  // keep the largest memory region (the actual framebuffer aperture)
348
352
  if (currentController.vram === null || vram > currentController.vram) {
349
353
  currentController.vram = vram;
@@ -374,7 +378,7 @@ function graphics(callback) {
374
378
  }
375
379
  return devices;
376
380
  }, {});
377
- for (let deviceId in devices) {
381
+ for (const deviceId in devices) {
378
382
  const device = devices[deviceId];
379
383
  if (device['CL_DEVICE_TYPE'] === 'CL_DEVICE_TYPE_GPU') {
380
384
  let busAddress;
@@ -429,24 +433,29 @@ function graphics(callback) {
429
433
 
430
434
  if (_windows) {
431
435
  try {
432
- const basePath = path.join(util.WINDIR, 'System32', 'DriverStore', 'FileRepository');
433
- // find all directories that have an nvidia-smi.exe file with date
434
- const candidates = fs
435
- .readdirSync(basePath, { withFileTypes: true })
436
- .filter((dir) => dir.isDirectory())
437
- .map((dir) => {
438
- const nvidiaSmiPath = path.join(basePath, dir.name, 'nvidia-smi.exe');
439
- try {
440
- const stats = fs.statSync(nvidiaSmiPath);
441
- return { path: nvidiaSmiPath, ctime: stats.ctimeMs };
442
- } catch {
443
- return null;
444
- }
445
- })
446
- .filter(Boolean);
447
- if (candidates.length > 0) {
448
- // take the most recent
449
- _nvidiaSmiPath = candidates.reduce((prev, curr) => (curr.ctime > prev.ctime ? curr : prev)).path;
436
+ const systemSmiPath = path.join(util.WINDIR, 'System32', 'nvidia-smi.exe');
437
+ if (fs.existsSync(systemSmiPath)) {
438
+ _nvidiaSmiPath = systemSmiPath;
439
+ } else {
440
+ const basePath = path.join(util.WINDIR, 'System32', 'DriverStore', 'FileRepository');
441
+ // find all directories that have an nvidia-smi.exe file with date
442
+ const candidates = fs
443
+ .readdirSync(basePath, { withFileTypes: true })
444
+ .filter((dir) => dir.isDirectory())
445
+ .map((dir) => {
446
+ const nvidiaSmiPath = path.join(basePath, dir.name, 'nvidia-smi.exe');
447
+ try {
448
+ const stats = fs.statSync(nvidiaSmiPath);
449
+ return { path: nvidiaSmiPath, ctime: stats.ctimeMs };
450
+ } catch {
451
+ return null;
452
+ }
453
+ })
454
+ .filter(Boolean);
455
+ if (candidates.length > 0) {
456
+ // take the most recent
457
+ _nvidiaSmiPath = candidates.reduce((prev, curr) => (curr.ctime > prev.ctime ? curr : prev)).path;
458
+ }
450
459
  }
451
460
  } catch {
452
461
  util.noop();
@@ -703,7 +712,7 @@ function graphics(callback) {
703
712
  currentRefreshRate: null
704
713
  };
705
714
  }
706
- let parts = lines[i].split(' ');
715
+ const parts = lines[i].split(' ');
707
716
  currentDisplay.connection = parts[0];
708
717
  currentDisplay.main = lines[i].toLowerCase().indexOf(' primary ') >= 0;
709
718
  currentDisplay.builtin = parts[0].toLowerCase().indexOf('edp') >= 0;
@@ -715,7 +724,7 @@ function graphics(callback) {
715
724
  edid_raw += lines[i].toLowerCase().trim();
716
725
  } else {
717
726
  // parsen EDID
718
- let edid_decoded = parseLinesLinuxEdid(edid_raw);
727
+ const edid_decoded = parseLinesLinuxEdid(edid_raw);
719
728
  currentDisplay.vendor = edid_decoded.vendor;
720
729
  currentDisplay.model = edid_decoded.model;
721
730
  currentDisplay.resolutionX = edid_decoded.resolutionX;
@@ -1068,7 +1077,7 @@ function graphics(callback) {
1068
1077
  function parseLinesWindowsControllers(sections, vections) {
1069
1078
  const memorySizes = {};
1070
1079
  for (const i in vections) {
1071
- if ({}.hasOwnProperty.call(vections, i)) {
1080
+ if (Object.hasOwn(vections, i)) {
1072
1081
  if (vections[i].trim() !== '') {
1073
1082
  const lines = vections[i].trim().split('\n');
1074
1083
  const matchingDeviceId = util.getValue(lines, 'MatchingDeviceId').match(/PCI\\(VEN_[0-9A-F]{4})&(DEV_[0-9A-F]{4})(?:&(SUBSYS_[0-9A-F]{8}))?(?:&(REV_[0-9A-F]{2}))?/i);
@@ -1091,7 +1100,7 @@ function graphics(callback) {
1091
1100
 
1092
1101
  const controllers = [];
1093
1102
  for (const i in sections) {
1094
- if ({}.hasOwnProperty.call(sections, i)) {
1103
+ if (Object.hasOwn(sections, i)) {
1095
1104
  if (sections[i].trim() !== '') {
1096
1105
  const lines = sections[i].trim().split('\n');
1097
1106
  const pnpDeviceId = util.getValue(lines, 'PNPDeviceID', ':').match(/PCI\\(VEN_[0-9A-F]{4})&(DEV_[0-9A-F]{4})(?:&(SUBSYS_[0-9A-F]{8}))?(?:&(REV_[0-9A-F]{2}))?/i);
@@ -1109,7 +1118,7 @@ function graphics(callback) {
1109
1118
  // PCI\VEN_v(4)&DEV_d(4)&SUBSYS_s(4)n(4)&REV_r(2)
1110
1119
  if (memorySize == null && pnpDeviceId[3] && pnpDeviceId[4]) {
1111
1120
  const deviceId = pnpDeviceId[1].toUpperCase() + '&' + pnpDeviceId[2].toUpperCase() + '&' + pnpDeviceId[3].toUpperCase() + '&' + pnpDeviceId[4].toUpperCase();
1112
- if ({}.hasOwnProperty.call(memorySizes, deviceId)) {
1121
+ if (Object.hasOwn(memorySizes, deviceId)) {
1113
1122
  memorySize = memorySizes[deviceId];
1114
1123
  }
1115
1124
  }
@@ -1117,7 +1126,7 @@ function graphics(callback) {
1117
1126
  // PCI\VEN_v(4)&DEV_d(4)&SUBSYS_s(4)n(4)
1118
1127
  if (memorySize == null && pnpDeviceId[3]) {
1119
1128
  const deviceId = pnpDeviceId[1].toUpperCase() + '&' + pnpDeviceId[2].toUpperCase() + '&' + pnpDeviceId[3].toUpperCase();
1120
- if ({}.hasOwnProperty.call(memorySizes, deviceId)) {
1129
+ if (Object.hasOwn(memorySizes, deviceId)) {
1121
1130
  memorySize = memorySizes[deviceId];
1122
1131
  }
1123
1132
  }
@@ -1125,7 +1134,7 @@ function graphics(callback) {
1125
1134
  // PCI\VEN_v(4)&DEV_d(4)&REV_r(2)
1126
1135
  if (memorySize == null && pnpDeviceId[4]) {
1127
1136
  const deviceId = pnpDeviceId[1].toUpperCase() + '&' + pnpDeviceId[2].toUpperCase() + '&' + pnpDeviceId[4].toUpperCase();
1128
- if ({}.hasOwnProperty.call(memorySizes, deviceId)) {
1137
+ if (Object.hasOwn(memorySizes, deviceId)) {
1129
1138
  memorySize = memorySizes[deviceId];
1130
1139
  }
1131
1140
  }
@@ -1133,7 +1142,7 @@ function graphics(callback) {
1133
1142
  // PCI\VEN_v(4)&DEV_d(4)
1134
1143
  if (memorySize == null) {
1135
1144
  const deviceId = pnpDeviceId[1].toUpperCase() + '&' + pnpDeviceId[2].toUpperCase();
1136
- if ({}.hasOwnProperty.call(memorySizes, deviceId)) {
1145
+ if (Object.hasOwn(memorySizes, deviceId)) {
1137
1146
  memorySize = memorySizes[deviceId];
1138
1147
  }
1139
1148
  }
package/lib/wifi.js CHANGED
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  // @ts-check
3
2
  // ==================================================================================
4
3
  // wifi.js
@@ -18,7 +17,7 @@ const exec = require('child_process').exec;
18
17
  const execSync = require('child_process').execSync;
19
18
  const util = require('./util');
20
19
 
21
- let _platform = process.platform;
20
+ const _platform = process.platform;
22
21
 
23
22
  const _linux = _platform === 'linux' || _platform === 'android';
24
23
  const _darwin = _platform === 'darwin';
@@ -117,13 +116,13 @@ const _wifi_frequencies = {
117
116
  };
118
117
 
119
118
  function wifiFrequencyFromChannel(channel) {
120
- return {}.hasOwnProperty.call(_wifi_frequencies, channel) ? _wifi_frequencies[channel] : null;
119
+ return Object.hasOwn(_wifi_frequencies, channel) ? _wifi_frequencies[channel] : null;
121
120
  }
122
121
 
123
122
  function wifiChannelFromFrequencs(frequency) {
124
123
  let channel = 0;
125
- for (let key in _wifi_frequencies) {
126
- if ({}.hasOwnProperty.call(_wifi_frequencies, key)) {
124
+ for (const key in _wifi_frequencies) {
125
+ if (Object.hasOwn(_wifi_frequencies, key)) {
127
126
  if (_wifi_frequencies[key] === frequency) {
128
127
  channel = util.toInt(key);
129
128
  }
@@ -190,30 +189,33 @@ function nmiDeviceLinux(iface) {
190
189
  try {
191
190
  const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
192
191
  const ssid = util.getValue(lines, 'GENERAL.CONNECTION');
192
+ const uuid = util.getValue(lines, 'GENERAL.CON-UUID');
193
193
  return {
194
194
  iface,
195
195
  type: util.getValue(lines, 'GENERAL.TYPE'),
196
196
  vendor: util.getValue(lines, 'GENERAL.VENDOR'),
197
197
  product: util.getValue(lines, 'GENERAL.PRODUCT'),
198
198
  mac: util.getValue(lines, 'GENERAL.HWADDR').toLowerCase(),
199
- ssid: ssid !== '--' ? ssid : null
199
+ ssid: ssid !== '--' ? ssid : null,
200
+ uuid: uuid !== '--' ? uuid : null
200
201
  };
201
202
  } catch {
202
203
  return {};
203
204
  }
204
205
  }
205
206
 
206
- function nmiConnectionLinux(ssid) {
207
- const ssidSanitized = sanitizeShellString(ssid, true);
208
- if (!ssidSanitized) {
207
+ function nmiConnectionLinux(uuid) {
208
+ // query by connection UUID instead of SSID: profile names may differ from the SSID
209
+ if (!uuid || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
209
210
  return {};
210
211
  }
211
- const cmd = `nmcli -t connection show ${ssidSanitized} 2>/dev/null`;
212
+ const cmd = `nmcli -t connection show ${uuid} 2>/dev/null`;
212
213
  try {
213
214
  const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
215
+ const ssid = util.getValue(lines, '802-11-wireless.ssid');
214
216
  const bssid = util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase();
215
217
  return {
216
- ssid: ssid !== '--' ? ssid : null,
218
+ ssid: ssid || null,
217
219
  uuid: util.getValue(lines, 'connection.uuid'),
218
220
  type: util.getValue(lines, 'connection.type'),
219
221
  autoconnect: util.getValue(lines, 'connection.autoconnect') === 'yes',
@@ -284,7 +286,9 @@ function getWifiNetworkListNmi() {
284
286
  function getWifiNetworkListIw(iface) {
285
287
  const result = [];
286
288
  try {
287
- let iwlistParts = execSync(`export LC_ALL=C; iwlist ${util.sanitizeString(iface, true)} scan 2>&1; unset LC_ALL`, util.execOptsLinux).toString().split(' Cell ');
289
+ const iwlistParts = execSync(`export LC_ALL=C; iwlist ${util.sanitizeString(iface, true)} scan 2>&1; unset LC_ALL`, util.execOptsLinux)
290
+ .toString()
291
+ .split(' Cell ');
288
292
  if (iwlistParts[0].indexOf('resource busy') >= 0) {
289
293
  return -1;
290
294
  }
@@ -585,11 +589,9 @@ function wifiConnections(callback) {
585
589
 
586
590
  const nmiDetails = nmiDeviceLinux(ifaceSanitized);
587
591
  const wpaDetails = wpaConnectionLinux(ifaceSanitized);
588
- const ssid = nmiDetails.ssid || wpaDetails.ssid;
592
+ const nmiConnection = nmiConnectionLinux(nmiDetails.uuid);
593
+ const ssid = nmiConnection.ssid || nmiDetails.ssid || wpaDetails.ssid;
589
594
  const network = networkList.filter((nw) => nw.ssid === ssid);
590
- const ssidSanitized = util.sanitizeString(ssid, true);
591
-
592
- const nmiConnection = nmiConnectionLinux(ssidSanitized);
593
595
  const channel = network && network.length && network[0].channel ? network[0].channel : wpaDetails.channel ? wpaDetails.channel : null;
594
596
  const bssid = network && network.length && network[0].bssid ? network[0].bssid : wpaDetails.bssid ? wpaDetails.bssid : null;
595
597
  const signalLevel = network && network.length && network[0].signalLevel ? network[0].signalLevel : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.31.16",
3
+ "version": "5.31.17",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",