systeminformation 6.0.0-beta.11 → 6.0.0-beta.12

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
@@ -461,7 +461,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
461
461
  | Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
462
462
  | -------------------------------- | ----------------- | ----- | --- | --- | --- | --- | --------------------------------------------------------------------------------------- |
463
463
  | si.currentLoad() | {...} | X | | X | X | X | CPU-Load |
464
- | | avgLoad | X | | X | | X | average load |
464
+ | | avgLoad | X | | X | X | X | average load<br>(Windows: approximated, see docs) |
465
465
  | | currentLoad | X | | X | X | X | CPU load in % |
466
466
  | | currentLoadUser | X | | X | X | X | CPU load user in % |
467
467
  | | currentLoadSystem | X | | X | X | X | CPU load system in % |
@@ -674,11 +674,10 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
674
674
  | | [0].revision | X | | | | | revision |
675
675
  | | [0].driver | X | | | | | driver |
676
676
  | | [0].default | | | X | X | | is default |
677
- | | [0].channel | X | | X | | | channel e.g. USB, HDMI, ... |
677
+ | | [0].channel | X | | X | X | | channel e.g. USB, HDMI, ... |
678
678
  | | [0].type | X | | X | X | | type e.g. Speaker |
679
- | | [0].in | | | X | X | | is input channel |
680
- | | [0].out | | | X | X | | is output channel |
681
- | | [0].interfaceType | X | | X | X | | interface type (PCIe, USB, HDMI, ...) |
679
+ | | [0].in | X | | X | X | | is input channel |
680
+ | | [0].out | X | | X | X | | is output channel |
682
681
  | | [0].status | X | | X | X | | status (e.g. active) |
683
682
 
684
683
  #### 12. Network related functions
@@ -688,11 +687,14 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
688
687
  | si.networkInterfaces() | [{...}] | X | X | X | X | X | array of network interfaces<br>With the 'default' parameter it returns<br>only the default interface |
689
688
  | | [0].iface | X | X | X | X | X | interface |
690
689
  | | [0].ifaceName | X | X | X | X | X | interface name (differs on Windows) |
690
+ | | [0].vendor | X | | X | X | | network adapter vendor (not available for every adapter) |
691
+ | | [0].model | X | | X | X | | network adapter model (not available for every adapter) |
691
692
  | | [0].default | X | X | X | X | X | true if this is the default interface |
692
693
  | | [0].ip4 | X | X | X | X | X | ip4 address |
693
694
  | | [0].ip4subnet | X | X | X | X | X | ip4 subnet mask |
694
695
  | | [0].ip6 | X | X | X | X | X | ip6 address |
695
696
  | | [0].ip6subnet | X | X | X | X | X | ip6 subnet mask |
697
+ | | [0].gateway | X | X | X | X | | default gateway of this interface |
696
698
  | | [0].mac | X | X | X | X | X | MAC address |
697
699
  | | [0].internal | X | X | X | X | X | true if internal interface |
698
700
  | | [0].virtual | X | X | X | X | X | true if virtual interface |
@@ -264,11 +264,14 @@ exports.initProcesses = {
264
264
  exports.initNetworkInterface = {
265
265
  iface: '',
266
266
  ifaceName: '',
267
+ vendor: '',
268
+ model: '',
267
269
  default: false,
268
270
  ip4: '',
269
271
  ip4subnet: '',
270
272
  ip6: '',
271
273
  ip6subnet: '',
274
+ gateway: '',
272
275
  mac: '',
273
276
  internal: true,
274
277
  virtual: false,
@@ -40,9 +40,6 @@ export declare const graphicsModelToVendor: (model: string) => string;
40
40
  export declare const graphicsIdToVendor: (id: string) => any;
41
41
  export declare const graphicsVendorToId: (str: string) => string;
42
42
  export declare const graphicsMetalVersion: (id: string) => any;
43
- export declare const winProcessStatus: {
44
- [index: string]: any;
45
- };
46
43
  export declare const getAppleModel: (key: string) => {
47
44
  key: string;
48
45
  model: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBluetoothVendor = exports.bluetoothVendors = exports.getAppleChassisType = exports.getAppleModel = exports.winProcessStatus = exports.graphicsMetalVersion = exports.graphicsVendorToId = exports.graphicsIdToVendor = exports.graphicsModelToVendor = exports.graphicsVideoTypes = exports.diskVendorFromModel = exports.chassisTypes = exports.wifiFrequencies = exports.socketTypes = exports.cpuBrandManufacturer = exports.getAMDSpeed = exports.cpuManufacturer = exports.getSocketTypesByName = exports.winPrinterStatus = exports.raspberryClockSpeed = exports.getMemManufacturer = exports.JEDEV_RAM_manufacturers = exports.getWindowsRelease = exports.getLogoFile = exports.wifiVendor = exports.usbWindowsType = exports.usbDarwinType = exports.usbLinuxType = exports.manufacturedApple = exports.bluetoothManufacturer = exports.bluetoothTypeLabel = exports.audioWindowsStatus = exports.audioDarwinChannelLabel = exports.audioTypeLabel = void 0;
3
+ exports.parseBluetoothVendor = exports.bluetoothVendors = exports.getAppleChassisType = exports.getAppleModel = exports.graphicsMetalVersion = exports.graphicsVendorToId = exports.graphicsIdToVendor = exports.graphicsModelToVendor = exports.graphicsVideoTypes = exports.diskVendorFromModel = exports.chassisTypes = exports.wifiFrequencies = exports.socketTypes = exports.cpuBrandManufacturer = exports.getAMDSpeed = exports.cpuManufacturer = exports.getSocketTypesByName = exports.winPrinterStatus = exports.raspberryClockSpeed = exports.getMemManufacturer = exports.JEDEV_RAM_manufacturers = exports.getWindowsRelease = exports.getLogoFile = exports.wifiVendor = exports.usbWindowsType = exports.usbDarwinType = exports.usbLinuxType = exports.manufacturedApple = exports.bluetoothManufacturer = exports.bluetoothTypeLabel = exports.audioWindowsStatus = exports.audioDarwinChannelLabel = exports.audioTypeLabel = void 0;
4
4
  const const_1 = require("./const");
5
5
  const speaker = 'Speaker';
6
6
  const microphone = 'Microphone';
@@ -1674,18 +1674,6 @@ const graphicsMetalVersion = (id) => {
1674
1674
  return families[id] || (version ? version[1] : '');
1675
1675
  };
1676
1676
  exports.graphicsMetalVersion = graphicsMetalVersion;
1677
- exports.winProcessStatus = {
1678
- '0': 'unknown',
1679
- '1': 'other',
1680
- '2': 'ready',
1681
- '3': 'running',
1682
- '4': 'blocked',
1683
- '5': 'suspended blocked',
1684
- '6': 'suspended ready',
1685
- '7': 'terminated',
1686
- '8': 'stopped',
1687
- '9': 'growing'
1688
- };
1689
1677
  const getAppleModel = (key) => {
1690
1678
  const appleModelIds = [
1691
1679
  {
@@ -943,11 +943,14 @@ export type ProcessLoadData = {
943
943
  export type NetworkInterfacesData = {
944
944
  iface: string;
945
945
  ifaceName: string;
946
+ vendor: string;
947
+ model: string;
946
948
  default: boolean;
947
949
  ip4: string;
948
950
  ip4subnet: string;
949
951
  ip6: string;
950
952
  ip6subnet: string;
953
+ gateway: string;
951
954
  mac: string;
952
955
  internal: boolean;
953
956
  virtual: boolean;
@@ -1,2 +1,3 @@
1
1
  import type { CurrentLoadData } from './common/types';
2
+ export declare const avgLoadEwma: (previous: number[] | null, busyCores: number, seconds: number) => number[];
2
3
  export declare const currentLoad: () => Promise<CurrentLoadData>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.currentLoad = void 0;
3
+ exports.currentLoad = exports.avgLoadEwma = void 0;
4
4
  const node_os_1 = require("node:os");
5
5
  const common_1 = require("./common");
6
6
  const const_1 = require("./common/const");
@@ -39,10 +39,24 @@ let _current_cpu = {
39
39
  };
40
40
  const _cpus = [];
41
41
  let _corecount = 0;
42
+ const AVG_LOAD_PERIODS = [60, 300, 900];
43
+ let _avgLoadEwma = [0, 0, 0];
44
+ let _avgLoadEwmaMs = null;
45
+ const avgLoadEwma = (previous, busyCores, seconds) => {
46
+ if (!previous || seconds <= 0) {
47
+ return [busyCores, busyCores, busyCores];
48
+ }
49
+ return AVG_LOAD_PERIODS.map((period, i) => {
50
+ const decay = Math.exp(-seconds / period);
51
+ return (previous[i] || 0) * decay + busyCores * (1 - decay);
52
+ });
53
+ };
54
+ exports.avgLoadEwma = avgLoadEwma;
55
+ const avgLoadFromEwma = (cores) => (cores ? parseFloat((Math.max(..._avgLoadEwma) / cores).toFixed(2)) : 0);
42
56
  const currentLoad = async () => {
43
57
  await (0, common_1.nextTick)();
44
58
  const loads = (0, node_os_1.loadavg)().map((x) => x / (0, node_os_1.cpus)().length);
45
- const avgLoad = parseFloat(Math.max(...loads).toFixed(2));
59
+ let avgLoad = parseFloat(Math.max(...loads).toFixed(2));
46
60
  let result = {
47
61
  avgLoad: 0,
48
62
  currentLoad: 0,
@@ -165,6 +179,13 @@ const currentLoad = async () => {
165
179
  const totalTick = totalUser + totalSystem + totalNice + totalIrq + totalSteal + totalGuest + totalIdle + totalIowait;
166
180
  const totalLoad = totalUser + totalSystem + totalNice + totalIrq + totalSteal + totalGuest;
167
181
  const currentTick = totalTick - _current_cpu.tick || 1;
182
+ if (const_1.WINDOWS) {
183
+ const busyCores = ((totalLoad - _current_cpu.load) / currentTick) * _corecount;
184
+ const seconds = _avgLoadEwmaMs === null ? 0 : (_current_cpu.ms - _avgLoadEwmaMs) / 1000;
185
+ _avgLoadEwma = (0, exports.avgLoadEwma)(_avgLoadEwmaMs === null ? null : _avgLoadEwma, busyCores, seconds);
186
+ _avgLoadEwmaMs = _current_cpu.ms;
187
+ avgLoad = avgLoadFromEwma(_corecount);
188
+ }
168
189
  result = {
169
190
  avgLoad: avgLoad,
170
191
  currentLoad: ((totalLoad - _current_cpu.load) / currentTick) * 100,
@@ -220,6 +241,9 @@ const currentLoad = async () => {
220
241
  };
221
242
  }
222
243
  else {
244
+ if (const_1.WINDOWS) {
245
+ avgLoad = avgLoadFromEwma(_corecount);
246
+ }
223
247
  const cores = [];
224
248
  for (let i = 0; i < _corecount; i++) {
225
249
  cores[i] = {};
@@ -1,2 +1,5 @@
1
1
  import type { NetworkInterfacesData } from '../common/types';
2
+ export declare const parseBsdGateways: (stdout: string) => {
3
+ [iface: string]: string;
4
+ };
2
5
  export declare const networkInterfaces: (defaultString?: string, rescan?: boolean) => Promise<NetworkInterfacesData[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.networkInterfaces = void 0;
3
+ exports.networkInterfaces = exports.parseBsdGateways = void 0;
4
4
  const node_os_1 = require("node:os");
5
5
  const common_1 = require("../common");
6
6
  const const_1 = require("../common/const");
@@ -97,6 +97,79 @@ const getBsdNics = async () => {
97
97
  return [];
98
98
  }
99
99
  };
100
+ const parseBsdGateways = (stdout) => {
101
+ const result = {};
102
+ let ifaceColumn = -1;
103
+ for (const line of stdout.split('\n')) {
104
+ const parts = line.trim().split(/\s+/);
105
+ if (parts[0] === 'Destination') {
106
+ ifaceColumn = parts.findIndex((part) => /^(netif|interface|iface)$/i.test(part));
107
+ continue;
108
+ }
109
+ if (parts[0] !== 'default' || parts.length < 3 || !parts[1].includes('.')) {
110
+ continue;
111
+ }
112
+ const iface = ifaceColumn > 0 ? parts[ifaceColumn] : parts.slice(2).reverse().find((part) => /^[a-z][a-z0-9]*\d$/.test(part));
113
+ if (iface && !result[iface]) {
114
+ result[iface] = parts[1];
115
+ }
116
+ }
117
+ return result;
118
+ };
119
+ exports.parseBsdGateways = parseBsdGateways;
120
+ const getBsdGateways = async () => {
121
+ try {
122
+ const { stdout } = await (0, exec_1.exec)('netstat -rn -f inet', { maxBuffer: const_1.MAX_BUFFER_SIZE });
123
+ return (0, exports.parseBsdGateways)(stdout);
124
+ }
125
+ catch {
126
+ return {};
127
+ }
128
+ };
129
+ let _nicVendors = null;
130
+ const getBsdNicVendors = async () => {
131
+ if (_nicVendors) {
132
+ return _nicVendors;
133
+ }
134
+ const result = {};
135
+ if (!const_1.DARWIN) {
136
+ _nicVendors = result;
137
+ return result;
138
+ }
139
+ let complete = false;
140
+ try {
141
+ const { stdout } = await (0, exec_1.exec)('ioreg -r -c IONetworkController -d 2 -w 0', { maxBuffer: const_1.MAX_BUFFER_SIZE });
142
+ let vendor = '';
143
+ let model = '';
144
+ for (const line of stdout.split('\n')) {
145
+ if (line.startsWith('+-o ')) {
146
+ vendor = '';
147
+ model = '';
148
+ continue;
149
+ }
150
+ const value = line.match(/"IO(Vendor|Model)" = "(.*)"/);
151
+ if (value) {
152
+ if (value[1] === 'Vendor') {
153
+ vendor = value[2];
154
+ }
155
+ else {
156
+ model = value[2];
157
+ }
158
+ continue;
159
+ }
160
+ const child = line.match(/^\s+\+-o (\S+)\s+<class \S*Interface/);
161
+ if (child && (vendor || model)) {
162
+ result[child[1]] = { vendor, model };
163
+ }
164
+ }
165
+ complete = true;
166
+ }
167
+ catch { }
168
+ if (complete) {
169
+ _nicVendors = result;
170
+ }
171
+ return result;
172
+ };
100
173
  const getBsdIfaceDHCPstatus = async (iface) => {
101
174
  let result = false;
102
175
  try {
@@ -118,8 +191,7 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
118
191
  _interfaces = (0, index_1.cloneObj)(interfaces);
119
192
  let result = [];
120
193
  try {
121
- const nics = await getBsdNics();
122
- const defaultInterface = await (0, network_interface_default_1.networkInterfaceDefault)();
194
+ const [nics, defaultInterface, gateways, vendors] = await Promise.all([getBsdNics(), (0, network_interface_default_1.networkInterfaceDefault)(), getBsdGateways(), getBsdNicVendors()]);
123
195
  for (const nic of nics) {
124
196
  let ip4link = '';
125
197
  let ip4linksubnet = '';
@@ -168,11 +240,14 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
168
240
  result.push({
169
241
  iface: nic.iface,
170
242
  ifaceName: nic.iface,
243
+ vendor: vendors[nic.iface]?.vendor || '',
244
+ model: vendors[nic.iface]?.model || '',
171
245
  default: nic.iface === defaultInterface,
172
246
  ip4: nic.ip4,
173
247
  ip4subnet: nic.ip4subnet || '',
174
248
  ip6: nic.ip6,
175
249
  ip6subnet: nic.ip6subnet || '',
250
+ gateway: gateways[nic.iface] || '',
176
251
  mac: nic.mac,
177
252
  internal: nic.internal,
178
253
  virtual: nic.internal ? false : (0, network_1.testVirtualNic)(nic.iface, nic.iface, nic.mac),
@@ -1,2 +1,3 @@
1
1
  import { DisplayData } from '../common/types';
2
+ export declare const drmDisplays: (path?: string) => Promise<DisplayData[]>;
2
3
  export declare const displays: () => Promise<DisplayData[]>;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displays = void 0;
3
+ exports.displays = exports.drmDisplays = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_path_1 = require("node:path");
4
6
  const common_1 = require("../common");
5
7
  const const_1 = require("../common/const");
6
8
  const defaults_1 = require("../common/defaults");
7
9
  const exec_1 = require("../common/exec");
10
+ const files_1 = require("../common/files");
8
11
  const index_1 = require("../common/index");
9
12
  const raspberry_1 = require("../common/raspberry");
13
+ const security_1 = require("../common/security");
10
14
  const parseLinesLinuxEdid = (edid) => {
11
15
  const result = (0, index_1.cloneObj)(defaults_1.initDisplay);
12
16
  let start = 108;
@@ -169,6 +173,51 @@ const getWorkAreaLinux = async (displays) => {
169
173
  catch { }
170
174
  return displays;
171
175
  };
176
+ const drmDisplays = async (path = '/sys/class/drm') => {
177
+ const result = [];
178
+ let connectors = [];
179
+ try {
180
+ connectors = (await (0, promises_1.readdir)(path)).filter((name) => /^card\d+-/.test(name) && (0, security_1.isSafePathSegment)(name)).sort();
181
+ }
182
+ catch {
183
+ return result;
184
+ }
185
+ for (const connector of connectors) {
186
+ const dir = (0, node_path_1.join)(path, connector);
187
+ if ((await (0, files_1.readSysfs)((0, node_path_1.join)(dir, 'status'))) !== 'connected') {
188
+ continue;
189
+ }
190
+ const display = (0, index_1.cloneObj)(defaults_1.initDisplay);
191
+ display.connection = connector.replace(/^card\d+-/, '');
192
+ display.builtin = /^(edp|lvds|dsi)/i.test(display.connection);
193
+ display.positionX = 0;
194
+ display.positionY = 0;
195
+ const mode = (await (0, files_1.readSysfs)((0, node_path_1.join)(dir, 'modes'))).split('\n')[0].split('x');
196
+ if (mode.length === 2) {
197
+ display.currentResX = (0, common_1.toInt)(mode[0]);
198
+ display.currentResY = (0, common_1.toInt)(mode[1]);
199
+ }
200
+ try {
201
+ const edid = (await (0, promises_1.readFile)((0, node_path_1.join)(dir, 'edid'))).toString('hex');
202
+ if (edid) {
203
+ const decoded = parseLinesLinuxEdid(edid);
204
+ display.model = decoded.model;
205
+ display.resolutionX = decoded.resolutionX;
206
+ display.resolutionY = decoded.resolutionY;
207
+ display.sizeX = decoded.sizeX;
208
+ display.sizeY = decoded.sizeY;
209
+ }
210
+ }
211
+ catch { }
212
+ result.push(display);
213
+ }
214
+ const main = result.find((display) => display.builtin) || result[0];
215
+ if (main) {
216
+ main.main = true;
217
+ }
218
+ return result;
219
+ };
220
+ exports.drmDisplays = drmDisplays;
172
221
  const displays = async () => {
173
222
  await (0, common_1.nextTick)();
174
223
  const result = [];
@@ -219,13 +268,17 @@ const displays = async () => {
219
268
  try {
220
269
  ({ stdout } = await (0, exec_1.exec)('xrandr --verbose 2>/dev/null', const_1.execOptsLinux));
221
270
  const lines = stdout.toString().split('\n');
222
- return await getWorkAreaLinux(parseLinesLinuxDisplays(lines, depth));
271
+ const xrandrDisplays = parseLinesLinuxDisplays(lines, depth);
272
+ if (xrandrDisplays.length) {
273
+ return await getWorkAreaLinux(xrandrDisplays);
274
+ }
223
275
  }
224
276
  catch { }
225
277
  }
226
278
  catch { }
227
279
  }
228
280
  catch { }
229
- return result;
281
+ const drm = await (0, exports.drmDisplays)();
282
+ return drm.length ? drm : result;
230
283
  };
231
284
  exports.displays = displays;
@@ -1,3 +1,4 @@
1
1
  import type { NetworkInterfacesData } from '../common/types';
2
2
  export declare const checkLinuxDCHPInterfaces: (file: string, depth?: number) => Promise<any[]>;
3
+ export declare const pciSlotFromPath: (path: string) => string | null;
3
4
  export declare const networkInterfaces: (defaultString?: string, rescan?: boolean) => Promise<NetworkInterfacesData[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.networkInterfaces = exports.checkLinuxDCHPInterfaces = void 0;
3
+ exports.networkInterfaces = exports.pciSlotFromPath = exports.checkLinuxDCHPInterfaces = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const node_os_1 = require("node:os");
6
6
  const node_path_1 = require("node:path");
@@ -13,6 +13,7 @@ const index_1 = require("../common/index");
13
13
  const network_1 = require("../common/network");
14
14
  const security_1 = require("../common/security");
15
15
  const network_interface_default_1 = require("./network-interface-default");
16
+ const pci_1 = require("./pci");
16
17
  let _interfaces = {};
17
18
  let _networkInterfaces = [];
18
19
  const splitSectionsNics = (lines) => {
@@ -194,6 +195,66 @@ const getLinuxIfaceIEEE8021xState = (authenticationProtocol) => {
194
195
  return 'Unknown';
195
196
  }
196
197
  };
198
+ const getLinuxGateways = async () => {
199
+ const result = {};
200
+ try {
201
+ const { stdout } = await (0, exec_1.exec)('ip -4 route show default 2> /dev/null', const_1.execOptsLinux);
202
+ for (const line of stdout.split('\n')) {
203
+ for (const match of line.matchAll(/(?:via\s+(\S+)\s+)?dev\s+(\S+)/g)) {
204
+ if (!result[match[2]]) {
205
+ result[match[2]] = match[1] || '';
206
+ }
207
+ }
208
+ }
209
+ }
210
+ catch { }
211
+ return result;
212
+ };
213
+ const PCI_SLOT = /^[0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}\.[0-9a-f]$/i;
214
+ const pciSlotFromPath = (path) => {
215
+ const segments = path.split('/');
216
+ return segments.slice(-2).reverse().find((segment) => PCI_SLOT.test(segment)) || null;
217
+ };
218
+ exports.pciSlotFromPath = pciSlotFromPath;
219
+ const _nicHardware = {};
220
+ const _nicHardwareChecked = new Set();
221
+ const getLinuxNicHardware = async (devices) => {
222
+ let pciDevices = null;
223
+ for (const device of devices) {
224
+ const dev = device.split(':')[0];
225
+ if (!(0, security_1.isSafePathSegment)(dev) || _nicHardwareChecked.has(dev)) {
226
+ continue;
227
+ }
228
+ let target = '';
229
+ try {
230
+ target = await (0, promises_1.realpath)(`/sys/class/net/${dev}/device`);
231
+ }
232
+ catch {
233
+ continue;
234
+ }
235
+ const [vendor, model] = await Promise.all([(0, files_1.readSysfs)((0, node_path_1.join)(target, '..', 'manufacturer')), (0, files_1.readSysfs)((0, node_path_1.join)(target, '..', 'product'))]);
236
+ if (vendor || model) {
237
+ _nicHardware[dev] = { vendor, model };
238
+ _nicHardwareChecked.add(dev);
239
+ continue;
240
+ }
241
+ const slot = (0, exports.pciSlotFromPath)(target);
242
+ if (!slot) {
243
+ _nicHardwareChecked.add(dev);
244
+ continue;
245
+ }
246
+ pciDevices = pciDevices || (await (0, pci_1.pci)());
247
+ if (!pciDevices.length) {
248
+ continue;
249
+ }
250
+ const entry = pciDevices.find((item) => item.slot && slot.endsWith(item.slot));
251
+ if (entry) {
252
+ _nicHardware[dev] = { vendor: entry.vendor, model: entry.model };
253
+ }
254
+ _nicHardwareChecked.add(dev);
255
+ }
256
+ return _nicHardware;
257
+ };
197
258
  const networkInterfaces = async (defaultString = '', rescan = true) => {
198
259
  await (0, common_1.nextTick)();
199
260
  const interfaces = (0, node_os_1.networkInterfaces)();
@@ -215,6 +276,8 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
215
276
  }
216
277
  }
217
278
  catch { }
279
+ const gateways = await getLinuxGateways();
280
+ const hardware = await getLinuxNicHardware(devices);
218
281
  for (const dev of devices) {
219
282
  const iface = dev;
220
283
  let ip4 = '';
@@ -313,11 +376,14 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
313
376
  ...defaults_1.initNetworkInterface,
314
377
  iface: ifaceSanitized,
315
378
  ifaceName,
379
+ vendor: hardware[ifaceSanitized]?.vendor || '',
380
+ model: hardware[ifaceSanitized]?.model || '',
316
381
  default: iface === defaultInterface,
317
382
  ip4,
318
383
  ip4subnet,
319
384
  ip6,
320
385
  ip6subnet,
386
+ gateway: gateways[ifaceSanitized] || '',
321
387
  mac,
322
388
  internal,
323
389
  virtual,
@@ -1,2 +1,31 @@
1
1
  import type { AudioData } from '../common/types';
2
+ type WindowsAudioEndpoint = {
3
+ f: string;
4
+ s: unknown;
5
+ r?: unknown;
6
+ l?: unknown;
7
+ n: string;
8
+ };
9
+ export declare const audioFlowNames: (endpoints: WindowsAudioEndpoint[], flow: string) => string[];
10
+ export declare const pickDefaultAudioNames: (endpoints: WindowsAudioEndpoint[]) => {
11
+ render: string | null;
12
+ capture: string | null;
13
+ };
14
+ export declare const matchesAudioDevice: (name: string, names: string[]) => boolean;
15
+ export declare const audioFlowFlags: (name: string, renderNames: string[], captureNames: string[]) => {
16
+ in: boolean;
17
+ out: boolean;
18
+ } | {
19
+ in: null;
20
+ out: null;
21
+ };
22
+ export declare const audioChannelWin: (pnpDeviceId: string, name: string) => "HDMI" | "USB" | "PCIe" | "Bluetooth" | "Onboard" | null;
23
+ export declare const audioDefaultFlag: (name: string, defaults: {
24
+ render: string | null;
25
+ capture: string | null;
26
+ }, flows: {
27
+ in: boolean | null;
28
+ out: boolean | null;
29
+ }) => boolean | null;
2
30
  export declare const audio: () => Promise<AudioData[]>;
31
+ export {};
@@ -1,23 +1,163 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.audio = void 0;
3
+ exports.audio = exports.audioDefaultFlag = exports.audioChannelWin = exports.audioFlowFlags = exports.matchesAudioDevice = exports.pickDefaultAudioNames = exports.audioFlowNames = void 0;
4
4
  const common_1 = require("../common");
5
5
  const defaults_1 = require("../common/defaults");
6
6
  const mappings_1 = require("../common/mappings");
7
7
  const windows_1 = require("../common/windows");
8
+ const MMDEVICES = 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio';
9
+ const NAME_KEYS = ['{b3f8fa53-0004-438e-9003-51a46e139bfc},6', '{a45c254e-df1c-4efd-8020-67d146a850e0},2', '{b3f8fa53-0004-438e-9003-51a46e139bfc},2'];
10
+ const WIN_AUDIO_ENDPOINTS = `@('Render','Capture') | ForEach-Object { $f=$_; Get-ChildItem "${MMDEVICES}\\$f" -ErrorAction SilentlyContinue | ForEach-Object { ` +
11
+ '$k=Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue; $p=Get-ItemProperty "$($_.PSPath)\\Properties" -ErrorAction SilentlyContinue; ' +
12
+ `[PSCustomObject]@{f=$f;s=$k.DeviceState;r=$k.'Role:0';l=$k.'Level:0';n=(@(${NAME_KEYS.map((key) => `$p.'${key}'`).join(',')}) -join ' ')} } } | ConvertTo-Json -Depth 4 -compress`;
13
+ const toRank = (value) => {
14
+ if (Array.isArray(value)) {
15
+ return value.length ? value.map((byte) => Number(byte) || 0) : null;
16
+ }
17
+ if (value === null || value === undefined || value === '') {
18
+ return null;
19
+ }
20
+ const numeric = Number(value);
21
+ if (!Number.isFinite(numeric) || numeric < 0) {
22
+ return null;
23
+ }
24
+ const bytes = [];
25
+ let rest = Math.floor(numeric);
26
+ for (let i = 0; i < 8; i++) {
27
+ bytes.push(rest % 256);
28
+ rest = Math.floor(rest / 256);
29
+ }
30
+ return bytes;
31
+ };
32
+ const compareRank = (a, b) => {
33
+ for (let i = Math.max(a.length, b.length) - 1; i >= 0; i--) {
34
+ const diff = (a[i] || 0) - (b[i] || 0);
35
+ if (diff) {
36
+ return diff;
37
+ }
38
+ }
39
+ return 0;
40
+ };
41
+ const pickMax = (entries, compare) => {
42
+ let best = entries[0];
43
+ let ambiguous = false;
44
+ for (const entry of entries.slice(1)) {
45
+ const diff = compare(entry.value, best.value);
46
+ if (diff > 0) {
47
+ best = entry;
48
+ ambiguous = false;
49
+ }
50
+ else if (diff === 0) {
51
+ ambiguous = true;
52
+ }
53
+ }
54
+ return ambiguous ? null : best.endpoint;
55
+ };
56
+ const bestEndpoint = (active) => {
57
+ if (active.length === 1) {
58
+ return active[0];
59
+ }
60
+ for (const key of ['r', 'l']) {
61
+ const ranked = [];
62
+ for (const endpoint of active) {
63
+ const value = toRank(endpoint[key]);
64
+ if (value) {
65
+ ranked.push({ endpoint, value });
66
+ }
67
+ }
68
+ const best = ranked.length ? pickMax(ranked, compareRank) : null;
69
+ if (best) {
70
+ return best;
71
+ }
72
+ }
73
+ return null;
74
+ };
75
+ const activeEndpoints = (endpoints, flow) => endpoints.filter((endpoint) => endpoint.f === flow && Number(endpoint.s) === 1 && (endpoint.n || '').trim());
76
+ const audioFlowNames = (endpoints, flow) => activeEndpoints(endpoints, flow).map((endpoint) => endpoint.n.trim().toLowerCase());
77
+ exports.audioFlowNames = audioFlowNames;
78
+ const endpointNames = (endpoint) => (endpoint?.n || '').trim().toLowerCase() || null;
79
+ const pickDefaultAudioNames = (endpoints) => ({
80
+ render: endpointNames(bestEndpoint(activeEndpoints(endpoints, 'Render'))),
81
+ capture: endpointNames(bestEndpoint(activeEndpoints(endpoints, 'Capture')))
82
+ });
83
+ exports.pickDefaultAudioNames = pickDefaultAudioNames;
84
+ const matchesAudioDevice = (name, names) => {
85
+ const needle = (name || '').trim().toLowerCase();
86
+ return needle.length > 2 && names.some((entry) => entry.includes(needle));
87
+ };
88
+ exports.matchesAudioDevice = matchesAudioDevice;
89
+ const audioFlowFlags = (name, renderNames, captureNames) => {
90
+ const out = (0, exports.matchesAudioDevice)(name, renderNames);
91
+ const isIn = (0, exports.matchesAudioDevice)(name, captureNames);
92
+ return out || isIn ? { in: isIn, out } : { in: null, out: null };
93
+ };
94
+ exports.audioFlowFlags = audioFlowFlags;
95
+ const audioChannelWin = (pnpDeviceId, name) => {
96
+ const id = (pnpDeviceId || '').toUpperCase();
97
+ const label = (name || '').toLowerCase();
98
+ if (label.includes('hdmi') || label.includes('displayport')) {
99
+ return 'HDMI';
100
+ }
101
+ if (id.startsWith('USB\\')) {
102
+ return 'USB';
103
+ }
104
+ if (id.startsWith('BTH')) {
105
+ return 'Bluetooth';
106
+ }
107
+ if (id.startsWith('HDAUDIO\\') || id.startsWith('INTELAUDIO\\')) {
108
+ return 'Onboard';
109
+ }
110
+ if (id.startsWith('PCI\\')) {
111
+ return 'PCIe';
112
+ }
113
+ return null;
114
+ };
115
+ exports.audioChannelWin = audioChannelWin;
116
+ const audioDefaultFlag = (name, defaults, flows) => {
117
+ const known = [defaults.render, defaults.capture].filter((entry) => Boolean(entry));
118
+ if ((0, exports.matchesAudioDevice)(name, known)) {
119
+ return true;
120
+ }
121
+ if (!known.length || (flows.out && !defaults.render) || (flows.in && !defaults.capture)) {
122
+ return null;
123
+ }
124
+ return false;
125
+ };
126
+ exports.audioDefaultFlag = audioDefaultFlag;
127
+ const getWindowsAudioEndpoints = async () => {
128
+ try {
129
+ return (0, windows_1.psArray)(await windows_1.ps.exec(WIN_AUDIO_ENDPOINTS));
130
+ }
131
+ catch {
132
+ return [];
133
+ }
134
+ };
8
135
  const audio = async () => {
9
136
  await (0, common_1.nextTick)();
10
137
  const defaults = (0, common_1.cloneObj)(defaults_1.initAudioResult);
11
- const devices = (0, windows_1.psArray)(await windows_1.ps.exec('Get-CimInstance Win32_SoundDevice | Select-Object DeviceID,StatusInfo,Name,Manufacturer | ConvertTo-Json -Depth 5'));
12
- return devices
138
+ const [deviceList, endpoints] = await Promise.all([
139
+ windows_1.ps.exec('Get-CimInstance Win32_SoundDevice | Select-Object DeviceID,PNPDeviceID,StatusInfo,Name,Manufacturer | ConvertTo-Json -Depth 5'),
140
+ getWindowsAudioEndpoints()
141
+ ]);
142
+ const defaultNames = (0, exports.pickDefaultAudioNames)(endpoints);
143
+ const renderNames = (0, exports.audioFlowNames)(endpoints, 'Render');
144
+ const captureNames = (0, exports.audioFlowNames)(endpoints, 'Capture');
145
+ return (0, windows_1.psArray)(deviceList)
13
146
  .filter((data) => data?.Name)
14
- .map((data) => ({
15
- ...defaults,
16
- id: data.DeviceID || '',
17
- name: data.Name,
18
- manufacturer: (data.Manufacturer || '').trim(),
19
- type: (0, mappings_1.audioTypeLabel)(data.Name),
20
- status: (0, mappings_1.audioWindowsStatus)(data.StatusInfo)
21
- }));
147
+ .map((data) => {
148
+ const flows = (0, exports.audioFlowFlags)(data.Name, renderNames, captureNames);
149
+ return {
150
+ ...defaults,
151
+ id: data.DeviceID || '',
152
+ name: data.Name,
153
+ manufacturer: (data.Manufacturer || '').trim(),
154
+ default: (0, exports.audioDefaultFlag)(data.Name, defaultNames, flows),
155
+ channel: (0, exports.audioChannelWin)(data.PNPDeviceID, data.Name),
156
+ type: (0, mappings_1.audioTypeLabel)(data.Name, Boolean(flows.in), Boolean(flows.out)),
157
+ in: flows.in,
158
+ out: flows.out,
159
+ status: (0, mappings_1.audioWindowsStatus)(data.StatusInfo)
160
+ };
161
+ });
22
162
  };
23
163
  exports.audio = audio;
@@ -34,9 +34,13 @@ const parseLinesWindowsNics = (sections, nconfigsections) => {
34
34
  }
35
35
  if (netEnabled !== '') {
36
36
  const speed = (0, common_1.toInt)((0, common_1.getValue)(lines, 'speed', ':').trim()) / 1000000;
37
+ const gateway = ((0, common_1.getValue)(linesNicConfig, 'DefaultIPGateway', ':').replace(/[{}"]/g, '').split(',')[0] || '').trim();
37
38
  nics.push({
38
39
  mac: (0, common_1.getValue)(lines, 'MACAddress', ':').toLowerCase(),
39
40
  dhcp: (0, common_1.getValue)(linesNicConfig, 'dhcpEnabled', ':').toLowerCase() === 'true',
41
+ gateway,
42
+ vendor: (0, common_1.getValue)(lines, 'Manufacturer', ':'),
43
+ model: (0, common_1.getValue)(lines, 'ProductName', ':') || (0, common_1.getValue)(lines, 'Description', ':'),
40
44
  name: ifacename,
41
45
  iface,
42
46
  netEnabled: netEnabled === 'TRUE',
@@ -54,7 +58,7 @@ const parseLinesWindowsNics = (sections, nconfigsections) => {
54
58
  };
55
59
  const getWindowsNics = async () => {
56
60
  let cmd = 'Get-CimInstance Win32_NetworkAdapter | fl *' + "; echo '#-#-#-#';";
57
- cmd += 'Get-CimInstance Win32_NetworkAdapterConfiguration | fl DHCPEnabled' + '';
61
+ cmd += 'Get-CimInstance Win32_NetworkAdapterConfiguration | fl DHCPEnabled, DefaultIPGateway' + '';
58
62
  try {
59
63
  const stdout = String((await windows_1.ps.exec(cmd)) || '');
60
64
  const data = stdout.split('#-#-#-#');
@@ -251,6 +255,9 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
251
255
  let speed = 0;
252
256
  let operstate = 'down';
253
257
  let dhcp = false;
258
+ let gateway = '';
259
+ let vendor = '';
260
+ let model = '';
254
261
  let dnsSuffix = '';
255
262
  let ieee8021xAuth = '';
256
263
  let ieee8021xState = '';
@@ -276,6 +283,9 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
276
283
  iface = detail.iface || iface;
277
284
  ifaceName = detail.name;
278
285
  dhcp = detail.dhcp;
286
+ gateway = detail.gateway;
287
+ vendor = detail.vendor;
288
+ model = detail.model;
279
289
  operstate = detail.operstate;
280
290
  speed = operstate === 'up' ? detail.speed : 0;
281
291
  type = detail.type;
@@ -303,11 +313,14 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
303
313
  ...defaults_1.initNetworkInterface,
304
314
  iface,
305
315
  ifaceName,
316
+ vendor,
317
+ model,
306
318
  default: iface === defaultInterface,
307
319
  ip4,
308
320
  ip4subnet,
309
321
  ip6,
310
322
  ip6subnet,
323
+ gateway,
311
324
  mac,
312
325
  internal,
313
326
  virtual,
@@ -1,4 +1,5 @@
1
1
  import type { CpuData, ProcessesData, ProcStatData } from '../common/types';
2
+ export declare const processStateWin: (running: number, waiting: number, suspended: number) => "unknown" | "running" | "blocked" | "sleeping";
2
3
  export declare const calcProcStatWin: (procStat: ProcStatData, all: number, _cpu_old: CpuData) => {
3
4
  pid: number;
4
5
  utime: number;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processes = exports.calcProcStatWin = void 0;
3
+ exports.processes = exports.calcProcStatWin = exports.processStateWin = void 0;
4
4
  const node_os_1 = require("node:os");
5
5
  const common_1 = require("../common");
6
6
  const defaults_1 = require("../common/defaults");
7
- const mappings_1 = require("../common/mappings");
8
7
  const windows_1 = require("../common/windows");
9
8
  const parse_1 = require("../common/parse");
10
9
  const _processes_cpu = {
@@ -15,6 +14,32 @@ const _processes_cpu = {
15
14
  ms: 0,
16
15
  result: {}
17
16
  };
17
+ const processStateWin = (running, waiting, suspended) => {
18
+ if (running > 0) {
19
+ return 'running';
20
+ }
21
+ if (waiting > 0) {
22
+ return 'sleeping';
23
+ }
24
+ if (suspended > 0) {
25
+ return 'blocked';
26
+ }
27
+ return 'unknown';
28
+ };
29
+ exports.processStateWin = processStateWin;
30
+ const WIN_THREAD_STATES = 'Get-Process -ErrorAction SilentlyContinue | ForEach-Object { $r=0;$w=0;$u=0; try { foreach ($t in $_.Threads) { $s=[int]$t.ThreadState; ' +
31
+ 'if ($s -eq 1 -or $s -eq 2 -or $s -eq 3 -or $s -eq 6) { $r++ } elseif ($s -eq 5) { if ([int]$t.WaitReason -eq 5) { $u++ } else { $w++ } } } } catch {}; ' +
32
+ '[PSCustomObject]@{i=$_.Id;r=$r;w=$w;u=$u} } | ConvertTo-Json -compress';
33
+ const getWindowsProcessStates = async () => {
34
+ const result = {};
35
+ try {
36
+ for (const entry of (0, windows_1.psArray)(await windows_1.ps.exec(WIN_THREAD_STATES))) {
37
+ result[entry.i] = (0, exports.processStateWin)(entry.r || 0, entry.w || 0, entry.u || 0);
38
+ }
39
+ }
40
+ catch { }
41
+ return result;
42
+ };
18
43
  const calcProcStatWin = (procStat, all, _cpu_old) => {
19
44
  let cpuu = 0;
20
45
  let cpus = 0;
@@ -43,8 +68,12 @@ const processes = async () => {
43
68
  if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
44
69
  const cpuBaseline = { ..._processes_cpu };
45
70
  try {
46
- const processArray = (0, windows_1.psArray)(await windows_1.ps.exec(`Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage,
47
- @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress`));
71
+ const [processList, states] = await Promise.all([
72
+ windows_1.ps.exec(`Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage,
73
+ @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress`),
74
+ getWindowsProcessStates()
75
+ ]);
76
+ const processArray = (0, windows_1.psArray)(processList);
48
77
  if (processArray.length) {
49
78
  const procs = [];
50
79
  const procStats = [];
@@ -54,7 +83,6 @@ const processes = async () => {
54
83
  processArray.forEach((element) => {
55
84
  const pid = element.ProcessId;
56
85
  const parentPid = element.ParentProcessId;
57
- const statusValue = element.ExecutionState || null;
58
86
  const name = element.Caption;
59
87
  const commandLine = element.CommandLine;
60
88
  const commandPath = element.ExecutablePath;
@@ -65,15 +93,6 @@ const processes = async () => {
65
93
  allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
66
94
  allcpus += stime - (cpuOld ? cpuOld.stime : 0);
67
95
  result.all++;
68
- if (!statusValue) {
69
- result.unknown++;
70
- }
71
- if (statusValue === 3) {
72
- result.running++;
73
- }
74
- if (statusValue === 4 || statusValue === 5) {
75
- result.blocked++;
76
- }
77
96
  procStats.push({
78
97
  pid: pid,
79
98
  name: '',
@@ -97,7 +116,7 @@ const processes = async () => {
97
116
  memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
98
117
  nice: 0,
99
118
  started: element.CreationDate,
100
- state: statusValue ? mappings_1.winProcessStatus[statusValue] : mappings_1.winProcessStatus[0],
119
+ state: states[pid] || 'unknown',
101
120
  tty: '',
102
121
  user: '',
103
122
  command: commandLine || name,
@@ -105,6 +124,9 @@ const processes = async () => {
105
124
  params: ''
106
125
  });
107
126
  });
127
+ result.running = procs.filter((proc) => proc.state === 'running').length;
128
+ result.blocked = procs.filter((proc) => proc.state === 'blocked').length;
129
+ result.unknown = procs.filter((proc) => proc.state === 'unknown').length;
108
130
  result.sleeping = result.all - result.running - result.blocked - result.unknown;
109
131
  result.list = procs;
110
132
  procStats.forEach((element) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.11",
3
+ "version": "6.0.0-beta.12",
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)",