systeminformation 6.0.0-beta.3 → 6.0.0-beta.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.
package/README.md CHANGED
@@ -380,6 +380,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
380
380
  | | [0].serial | | | X | X | | serial number |
381
381
  | | [0].displayId | | | X | X | | display ID |
382
382
  | | [0].main | X | | X | X | | true if main monitor |
383
+ | | [0].mirror | X | | X | X | | true if mirrored / duplicated |
383
384
  | | [0].builtin | X | | X | | | true if built-in monitor |
384
385
  | | [0].connection | X | | X | X | | e.g. DisplayPort or HDMI |
385
386
  | | [0].sizeX | X | | | X | | size in mm horizontal |
@@ -392,6 +393,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
392
393
  | | [0].positionX | X | | X | X | | display position X |
393
394
  | | [0].positionY | X | | X | X | | display position Y |
394
395
  | | [0].currentRefreshRate | X | | X | X | | current screen refresh rate |
396
+ | | [0].scale | | | | X | | DPI scaling factor, e.g. 1.5 |
395
397
 
396
398
  #### 7. Operating System
397
399
 
@@ -236,7 +236,8 @@ exports.initDisplay = {
236
236
  currentResY: null,
237
237
  positionX: 0,
238
238
  positionY: 0,
239
- currentRefreshRate: null
239
+ currentRefreshRate: null,
240
+ scale: null
240
241
  };
241
242
  exports.initProcesses = {
242
243
  all: 0,
@@ -63,7 +63,7 @@ const execSave = async (cmd, options = {}) => {
63
63
  return { stdout: stdout.toString(), stderr: stderr.toString() };
64
64
  }
65
65
  catch (e) {
66
- return { stdout: e.stdout, stderr: e.stderr };
66
+ return { stdout: String(e.stdout ?? ''), stderr: String(e.stderr ?? '') };
67
67
  }
68
68
  };
69
69
  exports.execSave = execSave;
@@ -824,6 +824,7 @@ export type DisplayData = {
824
824
  positionX: number;
825
825
  positionY: number;
826
826
  currentRefreshRate: number | null;
827
+ scale: number | null;
827
828
  };
828
829
  export type GpuNvidiaData = {
829
830
  driverVersion: string;
@@ -38,7 +38,8 @@ const parseDisplaysDarwin = (graphicsArr) => {
38
38
  currentResY: currentResolution.length > 1 ? parseInt(currentResolution[1], 10) : null,
39
39
  positionX: 0,
40
40
  positionY: 0,
41
- currentRefreshRate: currentResolutionParts.length > 1 ? parseInt(currentResolutionParts[1], 10) : null
41
+ currentRefreshRate: currentResolutionParts.length > 1 ? parseInt(currentResolutionParts[1], 10) : null,
42
+ scale: null
42
43
  });
43
44
  });
44
45
  }
@@ -171,7 +171,8 @@ const displays = async () => {
171
171
  currentResY: null,
172
172
  positionX: 0,
173
173
  positionY: 0,
174
- currentRefreshRate: null
174
+ currentRefreshRate: null,
175
+ scale: null
175
176
  });
176
177
  }
177
178
  }
@@ -114,7 +114,7 @@ const processLoad = async (proc) => {
114
114
  cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
115
115
  }
116
116
  }
117
- ({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
117
+ ({ stdout } = await (0, exec_1.execSave)(cmd, const_1.execOptsLinux));
118
118
  let curr_processes = stdout.toString().split('\n');
119
119
  const all = (0, parse_1.parseProcStat)(curr_processes[0]);
120
120
  curr_processes = curr_processes.slice(1);
@@ -281,7 +281,7 @@ const processes = async () => {
281
281
  }
282
282
  ({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
283
283
  if (stdout.trim()) {
284
- const lines = stdout.trim().split('\n');
284
+ const lines = stdout.split('\n');
285
285
  const parsedhead = (0, parse_1.parseHead)(lines[0], 8);
286
286
  result.list = (await parseProcesses(lines, parsedhead)).slice();
287
287
  result.all = result.list.length;
@@ -293,7 +293,7 @@ const processes = async () => {
293
293
  result.list.forEach((element) => {
294
294
  cmd += ';cat /proc/' + element.pid + '/stat';
295
295
  });
296
- ({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
296
+ ({ stdout } = await (0, exec_1.execSave)(cmd, const_1.execOptsLinux));
297
297
  let curr_processes = stdout.toString().split('\n');
298
298
  const all = (0, parse_1.parseProcStat)(curr_processes[0]);
299
299
  curr_processes = curr_processes.slice(1);
@@ -89,7 +89,7 @@ const calcServicesCpuLinux = async (result) => {
89
89
  cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
90
90
  }
91
91
  }
92
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
92
+ const { stdout } = await (0, exec_1.execSave)(cmd, const_1.execOptsLinux);
93
93
  let curr_processes = stdout.toString().split('\n');
94
94
  const all = (0, parse_1.parseProcStat)(curr_processes[0]);
95
95
  curr_processes = curr_processes.slice(1);
@@ -5,7 +5,7 @@ const common_1 = require("../common");
5
5
  const mappings_1 = require("../common/mappings");
6
6
  const exec_1 = require("../common/exec");
7
7
  const windows_1 = require("../common/windows");
8
- const psCurrentModes = "Add-Type -AssemblyName System.Windows.Forms; if (-not ('SiDevMode' -as [Type])) { Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]public struct SIDEVMODE{[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmDeviceName;public short dmSpecVersion;public short dmDriverVersion;public short dmSize;public short dmDriverExtra;public int dmFields;public int dmPositionX;public int dmPositionY;public int dmDisplayOrientation;public int dmDisplayFixedOutput;public short dmColor;public short dmDuplex;public short dmYResolution;public short dmTTOption;public short dmCollate;[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmFormName;public short dmLogPixels;public int dmBitsPerPel;public int dmPelsWidth;public int dmPelsHeight;public int dmDisplayFlags;public int dmDisplayFrequency;public int dmICMMethod;public int dmICMIntent;public int dmMediaType;public int dmDitherType;public int dmReserved1;public int dmReserved2;public int dmPanningWidth;public int dmPanningHeight;}public class SiDevMode{[DllImport(\"user32.dll\",CharSet=CharSet.Ansi)]public static extern bool EnumDisplaySettings(string lpszDeviceName,int iModeNum,ref SIDEVMODE lpDevMode);}' }; [System.Windows.Forms.Screen]::AllScreens | ForEach-Object { $dm = New-Object SIDEVMODE; $dm.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($dm); if ([SiDevMode]::EnumDisplaySettings($_.DeviceName, -1, [ref]$dm)) { $_.DeviceName + '|' + $dm.dmDisplayFrequency + '|' + $dm.dmBitsPerPel + '|' + $dm.dmPelsWidth + '|' + $dm.dmPelsHeight } }";
8
+ const psCurrentModes = "Add-Type -AssemblyName System.Windows.Forms; if (-not ('SiDevMode' -as [Type])) { Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]public struct SIDEVMODE{[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmDeviceName;public short dmSpecVersion;public short dmDriverVersion;public short dmSize;public short dmDriverExtra;public int dmFields;public int dmPositionX;public int dmPositionY;public int dmDisplayOrientation;public int dmDisplayFixedOutput;public short dmColor;public short dmDuplex;public short dmYResolution;public short dmTTOption;public short dmCollate;[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmFormName;public short dmLogPixels;public int dmBitsPerPel;public int dmPelsWidth;public int dmPelsHeight;public int dmDisplayFlags;public int dmDisplayFrequency;public int dmICMMethod;public int dmICMIntent;public int dmMediaType;public int dmDitherType;public int dmReserved1;public int dmReserved2;public int dmPanningWidth;public int dmPanningHeight;}public class SiDevMode{[DllImport(\"user32.dll\",CharSet=CharSet.Ansi)]public static extern bool EnumDisplaySettings(string lpszDeviceName,int iModeNum,ref SIDEVMODE lpDevMode);}' }; [System.Windows.Forms.Screen]::AllScreens | ForEach-Object { $dm = New-Object SIDEVMODE; $dm.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($dm); if ([SiDevMode]::EnumDisplaySettings($_.DeviceName, -1, [ref]$dm)) { $_.DeviceName + '|' + $dm.dmDisplayFrequency + '|' + $dm.dmBitsPerPel + '|' + $dm.dmPelsWidth + '|' + $dm.dmPelsHeight + '|' + $dm.dmPositionX + '|' + $dm.dmPositionY } }";
9
9
  const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, connections, isections, currentModes) => {
10
10
  const displays = [];
11
11
  const desktopMonitors = (dsections || []).map((section) => {
@@ -33,6 +33,13 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
33
33
  const sizeY = monitor ? monitor.sizeY : '';
34
34
  const videoOutputTechnology = instanceName && connections[instanceName] !== undefined ? connections[instanceName] : '';
35
35
  const deviceName = (0, common_1.getValue)(linesScreen, 'DeviceName');
36
+ const mode = currentModes[deviceName.toLowerCase()];
37
+ const boundsWidth = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':'));
38
+ const boundsHeight = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':'));
39
+ const boundsX = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'X', ':'));
40
+ const boundsY = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Y', ':'));
41
+ const resX = mode ? mode.width : boundsWidth;
42
+ const resY = mode ? mode.height : boundsHeight;
36
43
  const isection = instanceName ? isections.find((element) => element.instanceId.toLowerCase().startsWith(instanceName)) : undefined;
37
44
  const dsection = instanceName ? desktopMonitors.find((element) => element.deviceId && instanceName.startsWith(element.deviceId)) : undefined;
38
45
  displays.push({
@@ -47,16 +54,17 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
47
54
  mirror: !hasOwnScreen || (monitors.length > ssections.length && i === 0),
48
55
  builtin: videoOutputTechnology === '2147483648',
49
56
  connection: videoOutputTechnology && mappings_1.graphicsVideoTypes[videoOutputTechnology] ? mappings_1.graphicsVideoTypes[videoOutputTechnology] : '',
50
- resolutionX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':')),
51
- resolutionY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':')),
57
+ resolutionX: resX,
58
+ resolutionY: resY,
52
59
  sizeX: sizeX ? parseInt(sizeX, 10) : null,
53
60
  sizeY: sizeY ? parseInt(sizeY, 10) : null,
54
61
  pixelDepth: bitsPerPixel,
55
- currentResX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':')),
56
- currentResY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':')),
57
- positionX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'X', ':')),
58
- positionY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Y', ':')),
59
- currentRefreshRate: currentModes[deviceName.toLowerCase()] || null
62
+ currentResX: resX,
63
+ currentResY: resY,
64
+ positionX: mode ? mode.positionX : boundsX,
65
+ positionY: mode ? mode.positionY : boundsY,
66
+ currentRefreshRate: (mode && mode.refreshRate) || null,
67
+ scale: mode && boundsWidth ? Math.round((mode.width / boundsWidth) * 100) / 100 : null
60
68
  });
61
69
  }
62
70
  }
@@ -83,7 +91,8 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
83
91
  currentResY: first ? first.resolutionY : 0,
84
92
  positionX: 0,
85
93
  positionY: 0,
86
- currentRefreshRate: null
94
+ currentRefreshRate: null,
95
+ scale: null
87
96
  });
88
97
  }
89
98
  return displays;
@@ -179,9 +188,15 @@ const displays = async () => {
179
188
  .split(/\n/)
180
189
  .forEach((element) => {
181
190
  const parts = element.split('|');
182
- const frequency = parts.length === 5 ? (0, common_1.toInt)(parts[1]) : 0;
183
- if (frequency > 1 && parts[0]) {
184
- currentModes[parts[0].trim().toLowerCase()] = frequency;
191
+ if (parts.length === 7 && parts[0].trim() && (0, common_1.toInt)(parts[3])) {
192
+ const frequency = (0, common_1.toInt)(parts[1]);
193
+ currentModes[parts[0].trim().toLowerCase()] = {
194
+ refreshRate: frequency > 1 ? frequency : 0,
195
+ width: (0, common_1.toInt)(parts[3]),
196
+ height: (0, common_1.toInt)(parts[4]),
197
+ positionX: (0, common_1.toInt)(parts[5]),
198
+ positionY: (0, common_1.toInt)(parts[6])
199
+ };
185
200
  }
186
201
  });
187
202
  result = parseLinesWindowsDisplaysPowershell(ssections, monitors, dsections, connections, isections, currentModes);
@@ -24,16 +24,17 @@ const processLoad = async (proc) => {
24
24
  const processArray = (0, windows_1.psArray)(await windows_1.ps.exec('Get-CimInstance Win32_Process | select ProcessId,Caption,UserModeTime,KernelModeTime,WorkingSetSize | ConvertTo-Json -compress'));
25
25
  const procStats = [];
26
26
  const list_new = {};
27
- let allcpuu = 0;
28
- let allcpus = 0;
27
+ let allcpuu = _process_cpu.all_utime;
28
+ let allcpus = _process_cpu.all_stime;
29
29
  processArray.forEach((element) => {
30
30
  const pid = element.ProcessId;
31
31
  const name = element.Caption;
32
32
  const utime = element.UserModeTime;
33
33
  const stime = element.KernelModeTime;
34
34
  const mem = element.WorkingSetSize;
35
- allcpuu = allcpuu + utime;
36
- allcpus = allcpus + stime;
35
+ const cpuOld = _process_cpu.list[pid];
36
+ allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
37
+ allcpus += stime - (cpuOld ? cpuOld.stime : 0);
37
38
  procStats.push({
38
39
  pid: pid,
39
40
  name,
@@ -18,12 +18,13 @@ const calcProcStatWin = (procStat, all, _cpu_old) => {
18
18
  let cpuu = 0;
19
19
  let cpus = 0;
20
20
  if (_cpu_old.all > 0 && _cpu_old.list[procStat.pid]) {
21
- cpuu = ((procStat.utime - _cpu_old.list[procStat.pid].utime) / (all - _cpu_old.all)) * 100;
22
- cpus = ((procStat.stime - _cpu_old.list[procStat.pid].stime) / (all - _cpu_old.all)) * 100;
21
+ const delta = all - _cpu_old.all;
22
+ cpuu = delta > 0 ? ((procStat.utime - _cpu_old.list[procStat.pid].utime) / delta) * 100 : 0;
23
+ cpus = delta > 0 ? ((procStat.stime - _cpu_old.list[procStat.pid].stime) / delta) * 100 : 0;
23
24
  }
24
25
  else {
25
- cpuu = (procStat.utime / all) * 100;
26
- cpus = (procStat.stime / all) * 100;
26
+ cpuu = all > 0 ? (procStat.utime / all) * 100 : 0;
27
+ cpus = all > 0 ? (procStat.stime / all) * 100 : 0;
27
28
  }
28
29
  return {
29
30
  pid: procStat.pid,
@@ -45,8 +46,8 @@ const processes = async () => {
45
46
  const procs = [];
46
47
  const procStats = [];
47
48
  const list_new = {};
48
- let allcpuu = 0;
49
- let allcpus = 0;
49
+ let allcpuu = _processes_cpu.all_utime;
50
+ let allcpus = _processes_cpu.all_stime;
50
51
  processArray.forEach((element) => {
51
52
  const pid = element.ProcessId;
52
53
  const parentPid = element.ParentProcessId;
@@ -57,8 +58,9 @@ const processes = async () => {
57
58
  const utime = element.UserModeTime;
58
59
  const stime = element.KernelModeTime;
59
60
  const memw = element.WorkingSetSize;
60
- allcpuu = allcpuu + utime;
61
- allcpus = allcpus + stime;
61
+ const cpuOld = _processes_cpu.list[pid];
62
+ allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
63
+ allcpus += stime - (cpuOld ? cpuOld.stime : 0);
62
64
  result.all++;
63
65
  if (!statusValue) {
64
66
  result.unknown++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.3",
3
+ "version": "6.0.0-beta.5",
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)",