systeminformation 6.0.0-beta.12 → 6.0.0-beta.13

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
@@ -373,6 +373,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
373
373
  | | [0].model | X | | X | X | | graphics controller model |
374
374
  | | [0].deviceId | | | X | | | device ID |
375
375
  | | [0].bus | X | | X | X | | on which bus (e.g. PCIe) |
376
+ | | [0].busAddress | X | | | X | | PCI bus address, e.g. '01:00.0' |
376
377
  | | [0].vram | X | | X | X | | VRAM size (in MB) |
377
378
  | | [0].vramDynamic | X | | X | X | | true if dynamically allocated ram |
378
379
  | | [0].external | | | X | | | is external GPU |
@@ -406,6 +407,9 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
406
407
  | | [0].workAreaPositionY | X | | X | X | | working area position Y |
407
408
  | | [0].currentRefreshRate | X | | X | X | | current screen refresh rate |
408
409
  | | [0].scale | | | | X | | DPI scaling factor, e.g. 1.5 |
410
+ | | [0].powerState | X | | | X | | 'on', 'standby', 'suspend', 'off' |
411
+ | | [0].gpu | | | X | X | | GPU model driving this display |
412
+ | | [0].gpuBusAddress | X | | | X | | PCI addr, joins gpu().busAddress |
409
413
 
410
414
  #### 7. Operating System
411
415
 
@@ -515,6 +519,10 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
515
519
  | | [0].pids | X | X | X | X | | pids |
516
520
  | | [0].cpu | X | X | X | | | process % CPU |
517
521
  | | [0].mem | X | X | X | | | process % MEM |
522
+ | si.processFocused() | {...} | X | | X | X | | process owning the currently focused window (X11 only on Linux); null if not detectable |
523
+ | | pid | X | | X | X | | PID of the focused process |
524
+ | | name | X | | X | X | | name of the focused process |
525
+ | | path | X | | X | X | | path of the focused process |
518
526
 
519
527
  #### 9. File System
520
528
 
@@ -539,7 +547,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
539
547
  | | [0].smartStatus | X | | X | X | | S.M.A.R.T Status (see Known Issues) |
540
548
  | | [0].temperature | X | | | | | S.M.A.R.T temperature |
541
549
  | | [0].smartData | X | | | X | | full S.M.A.R.T data from smartctl<br>requires at least smartmontools 7.0 |
542
- | si.blockDevices() | [{...}] | X | | X | X | | returns array of disks, partitions,<br>raids and roms |
550
+ | si.blockDevices() | [{...}] | X | | X | X | | returns array of disks, partitions,<br>raids, pools and roms |
543
551
  | | [0].name | X | | X | X | | name |
544
552
  | | [0].type | X | | X | X | | type |
545
553
  | | [0].fstype | X | | X | X | | file system type (e.g. ext4) |
@@ -552,7 +560,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
552
560
  | | [0].serial | X | | | X | | serial |
553
561
  | | [0].removable | X | | X | X | | serial |
554
562
  | | [0].protocol | X | | X | | | protocol (SATA, PCI-Express, ...) |
555
- | | [0].group | X | | | | | Raid group member (e.g. md1) |
563
+ | | [0].group | X | | | | | raid / pool member (e.g. md1, ZFS pool,<br>btrfs label) |
556
564
  | | [0].device | X | | X | X | | physical device mapped to (e.g. /dev/sda) |
557
565
  | si.disksIO() | {...} | X | | X | X | | current transfer stats |
558
566
  | | rIO | X | | X | X | | read IOs on all mounted drives |
@@ -7,6 +7,7 @@ const security_1 = require("../common/security");
7
7
  const defaults_1 = require("../common/defaults");
8
8
  const darwin_1 = require("../darwin");
9
9
  const network_1 = require("../common/network");
10
+ const EXEC_OPTS = { timeout: 5000 };
10
11
  const _network = {};
11
12
  const networkStatsSingle = async (iface) => {
12
13
  const defaults = { ...defaults_1.initNetworkSpeed, iface };
@@ -18,7 +19,7 @@ const networkStatsSingle = async (iface) => {
18
19
  let rx_errors = 0;
19
20
  let tx_dropped = 0;
20
21
  let tx_errors = 0;
21
- const stdout = await (0, exec_1.execSecure)('netstat', ['-ibndI', iface]);
22
+ const stdout = await (0, exec_1.execSecure)('netstat', ['-ibndI', iface], EXEC_OPTS);
22
23
  if (stdout) {
23
24
  const lines = stdout.split('\n');
24
25
  for (let i = 1; i < lines.length; i++) {
@@ -251,7 +251,10 @@ exports.initDisplay = {
251
251
  workAreaPositionX: null,
252
252
  workAreaPositionY: null,
253
253
  currentRefreshRate: null,
254
- scale: null
254
+ scale: null,
255
+ powerState: '',
256
+ gpu: '',
257
+ gpuBusAddress: ''
255
258
  };
256
259
  exports.initProcesses = {
257
260
  all: 0,
@@ -19,3 +19,22 @@ export declare const parseLinuxBlk: (lines: string[]) => FsBlockDevicesData[];
19
19
  export declare const raidMatchLinux: (data: FsBlockDevicesData[]) => Promise<FsBlockDevicesData[]>;
20
20
  export declare const matchDevicesLinux: (data: FsBlockDevicesData[]) => FsBlockDevicesData[];
21
21
  export declare const matchDevicesWin: (data: FsBlockDevicesData[], diskDrives: string[]) => FsBlockDevicesData[];
22
+ export type PoolInfoLinux = {
23
+ name: string;
24
+ type: string;
25
+ fsType: string;
26
+ size: number;
27
+ uuid: string;
28
+ mount: string;
29
+ members: string[];
30
+ };
31
+ export declare const parseZpoolStatus: (stdout: string) => Map<string, {
32
+ type: string;
33
+ members: string[];
34
+ }>;
35
+ export declare const parseZpoolList: (stdout: string) => Map<string, number>;
36
+ export declare const btrfsProfileFromEntries: (entries: string[]) => string;
37
+ export declare const applyPoolsLinux: (data: FsBlockDevicesData[], pools: PoolInfoLinux[]) => FsBlockDevicesData[];
38
+ export declare const parseZfsMountpoints: (content: string) => Map<string, string>;
39
+ export declare const zfsPoolsLinux: (data: FsBlockDevicesData[]) => Promise<PoolInfoLinux[]>;
40
+ export declare const btrfsPoolsLinux: (data: FsBlockDevicesData[]) => Promise<PoolInfoLinux[]>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = exports.zfsDatasets = void 0;
3
+ exports.btrfsPoolsLinux = exports.zfsPoolsLinux = exports.parseZfsMountpoints = exports.applyPoolsLinux = exports.btrfsProfileFromEntries = exports.parseZpoolList = exports.parseZpoolStatus = exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = exports.zfsDatasets = void 0;
4
+ const promises_1 = require("node:fs/promises");
4
5
  const index_1 = require("./index");
5
6
  const const_1 = require("./const");
6
7
  const defaults_1 = require("./defaults");
7
8
  const exec_1 = require("./exec");
9
+ const security_1 = require("./security");
8
10
  let _smartMonToolsInstalled = null;
9
11
  const zfsDatasets = async () => {
10
12
  const byMount = new Map();
@@ -235,7 +237,10 @@ const raidMatchLinux = async (data) => {
235
237
  try {
236
238
  for (const element of data) {
237
239
  if (element.type.startsWith('raid')) {
238
- const stdout = await (0, exec_1.execSecure)('mdadm', ['--export', '--detail', `/dev/${element.name}`]);
240
+ if (!(0, security_1.isSafePathSegment)(element.name)) {
241
+ continue;
242
+ }
243
+ const stdout = await (0, exec_1.execSecure)('mdadm', ['--export', '--detail', `/dev/${element.name}`], { timeout: 5000 });
239
244
  const lines = stdout.split('\n');
240
245
  const mdData = decodeMdabmData(lines);
241
246
  element.label = mdData.label;
@@ -311,3 +316,163 @@ const matchDevicesWin = (data, diskDrives) => {
311
316
  return data;
312
317
  };
313
318
  exports.matchDevicesWin = matchDevicesWin;
319
+ const ZFS_VDEV_TYPES = ['mirror', 'raidz', 'draid'];
320
+ const parseZpoolStatus = (stdout) => {
321
+ const result = new Map();
322
+ let pool = '';
323
+ let inConfig = false;
324
+ for (const line of stdout.split('\n')) {
325
+ const trimmed = line.trim();
326
+ if (trimmed.startsWith('pool:')) {
327
+ pool = trimmed.substring(5).trim();
328
+ inConfig = false;
329
+ continue;
330
+ }
331
+ if (!pool) {
332
+ continue;
333
+ }
334
+ if (trimmed === 'config:') {
335
+ inConfig = true;
336
+ result.set(pool, { type: 'stripe', members: [] });
337
+ continue;
338
+ }
339
+ if (!inConfig || !trimmed || trimmed.startsWith('errors:')) {
340
+ inConfig = inConfig && !trimmed.startsWith('errors:');
341
+ continue;
342
+ }
343
+ const entry = result.get(pool);
344
+ const token = trimmed.split(/\s+/)[0];
345
+ if (!entry || token === 'NAME' || token === pool) {
346
+ continue;
347
+ }
348
+ if (token.startsWith('/')) {
349
+ entry.members.push(token.split('/').pop() || '');
350
+ }
351
+ else if (entry.type === 'stripe' && !entry.members.length && ZFS_VDEV_TYPES.some((type) => token.startsWith(type))) {
352
+ entry.type = token.replace(/-\d+$/, '');
353
+ }
354
+ }
355
+ return result;
356
+ };
357
+ exports.parseZpoolStatus = parseZpoolStatus;
358
+ const parseZpoolList = (stdout) => {
359
+ const result = new Map();
360
+ for (const line of stdout.split('\n')) {
361
+ const parts = line.split('\t');
362
+ if (parts.length < 2 || !parts[0].trim()) {
363
+ continue;
364
+ }
365
+ result.set(parts[0].trim(), (0, index_1.toInt)(parts[1]));
366
+ }
367
+ return result;
368
+ };
369
+ exports.parseZpoolList = parseZpoolList;
370
+ const BTRFS_PROFILES = ['raid1c4', 'raid1c3', 'raid10', 'raid0', 'raid5', 'raid6', 'raid1', 'dup', 'single'];
371
+ const btrfsProfileFromEntries = (entries) => BTRFS_PROFILES.find((profile) => entries.includes(profile)) || '';
372
+ exports.btrfsProfileFromEntries = btrfsProfileFromEntries;
373
+ const applyPoolsLinux = (data, pools) => {
374
+ const defaults = (0, index_1.cloneObj)(defaults_1.initFsBlockDevice);
375
+ const result = [...data];
376
+ for (const pool of pools) {
377
+ const members = result.filter((element) => pool.members.includes(element.name));
378
+ if (!members.length) {
379
+ continue;
380
+ }
381
+ for (const member of members) {
382
+ member.group = pool.name;
383
+ }
384
+ result.push({
385
+ ...defaults,
386
+ name: pool.name,
387
+ type: pool.type,
388
+ fsType: pool.fsType,
389
+ mount: pool.mount,
390
+ size: pool.size,
391
+ uuid: pool.uuid
392
+ });
393
+ }
394
+ return result;
395
+ };
396
+ exports.applyPoolsLinux = applyPoolsLinux;
397
+ const parseZfsMountpoints = (content) => {
398
+ const result = new Map();
399
+ for (const line of content.split('\n')) {
400
+ const parts = line.split(' ');
401
+ if (parts.length < 3 || parts[2] !== 'zfs' || parts[0].includes('/')) {
402
+ continue;
403
+ }
404
+ result.set(parts[0], parts[1].replace(/\\(\d{3})/g, (_, code) => String.fromCharCode(parseInt(code, 8))));
405
+ }
406
+ return result;
407
+ };
408
+ exports.parseZfsMountpoints = parseZfsMountpoints;
409
+ const zfsPoolsLinux = async (data) => {
410
+ const result = [];
411
+ if (!data.some((element) => element.fsType === 'zfs_member')) {
412
+ return result;
413
+ }
414
+ try {
415
+ const status = (0, exports.parseZpoolStatus)(await (0, exec_1.execSecure)('zpool', ['status', '-PL'], { timeout: 5000 }));
416
+ if (!status.size) {
417
+ return result;
418
+ }
419
+ const sizes = (0, exports.parseZpoolList)(await (0, exec_1.execSecure)('zpool', ['list', '-Hp', '-o', 'name,size'], { timeout: 5000 }));
420
+ const mountpoints = (0, exports.parseZfsMountpoints)(await (0, promises_1.readFile)('/proc/mounts', 'utf8').catch(() => ''));
421
+ for (const [name, info] of status) {
422
+ const members = data.filter((element) => info.members.includes(element.name));
423
+ result.push({
424
+ name,
425
+ type: info.type,
426
+ fsType: 'zfs',
427
+ size: sizes.get(name) || members.reduce((sum, element) => sum + element.size, 0),
428
+ uuid: '',
429
+ mount: mountpoints.get(name) || '',
430
+ members: info.members
431
+ });
432
+ }
433
+ }
434
+ catch { }
435
+ return result;
436
+ };
437
+ exports.zfsPoolsLinux = zfsPoolsLinux;
438
+ const BTRFS_SYSFS = '/sys/fs/btrfs';
439
+ const btrfsPoolsLinux = async (data) => {
440
+ const result = [];
441
+ let fsids = [];
442
+ try {
443
+ fsids = (await (0, promises_1.readdir)(BTRFS_SYSFS)).filter(security_1.isSafePathSegment);
444
+ }
445
+ catch {
446
+ return result;
447
+ }
448
+ for (const fsid of fsids) {
449
+ let devices = [];
450
+ try {
451
+ devices = await (0, promises_1.readdir)(`${BTRFS_SYSFS}/${fsid}/devices`);
452
+ }
453
+ catch {
454
+ continue;
455
+ }
456
+ if (devices.length < 2) {
457
+ continue;
458
+ }
459
+ let profile = '';
460
+ try {
461
+ profile = (0, exports.btrfsProfileFromEntries)(await (0, promises_1.readdir)(`${BTRFS_SYSFS}/${fsid}/allocation/data`));
462
+ }
463
+ catch { }
464
+ const label = (await (0, promises_1.readFile)(`${BTRFS_SYSFS}/${fsid}/label`, 'utf8').catch(() => '')).trim();
465
+ const members = data.filter((element) => devices.includes(element.name));
466
+ result.push({
467
+ name: label || fsid,
468
+ type: profile || 'btrfs',
469
+ fsType: 'btrfs',
470
+ size: members.reduce((sum, element) => sum + element.size, 0),
471
+ uuid: fsid,
472
+ mount: members.find((element) => element.mount)?.mount || '',
473
+ members: devices
474
+ });
475
+ }
476
+ return result;
477
+ };
478
+ exports.btrfsPoolsLinux = btrfsPoolsLinux;
@@ -851,6 +851,9 @@ export type DisplayData = {
851
851
  workAreaPositionY: number | null;
852
852
  currentRefreshRate: number | null;
853
853
  scale: number | null;
854
+ powerState: string;
855
+ gpu: string;
856
+ gpuBusAddress: string;
854
857
  };
855
858
  export type GpuNvidiaData = {
856
859
  driverVersion: string;
@@ -933,6 +936,11 @@ export type ProcessesData = {
933
936
  unknown: number;
934
937
  list: ProcessesProcessData[];
935
938
  };
939
+ export type ProcessFocusedData = {
940
+ pid: number;
941
+ name: string;
942
+ path: string;
943
+ };
936
944
  export type ProcessLoadData = {
937
945
  proc: string;
938
946
  pid: number | null;
@@ -55,4 +55,8 @@ declare class PowerShellPool {
55
55
  }
56
56
  export declare const psArray: (value: any) => any[];
57
57
  export declare const ps: PowerShellPool;
58
+ export declare const parseWindowsLocationInfo: (value: string) => string;
59
+ export declare const parseWindowsPnpLocations: (stdout: any) => Map<string, string>;
60
+ export declare const matchPnpLocation: (deviceId: string, locations: Map<string, string>) => string;
61
+ export declare const windowsPciBusAddresses: () => Promise<Map<string, string>>;
58
62
  export {};
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ps = exports.psArray = void 0;
3
+ exports.windowsPciBusAddresses = exports.matchPnpLocation = exports.parseWindowsPnpLocations = exports.parseWindowsLocationInfo = exports.ps = exports.psArray = void 0;
4
4
  const node_child_process_1 = require("node:child_process");
5
+ const exec_1 = require("./exec");
5
6
  const files_1 = require("../common/files");
6
7
  const const_1 = require("./const");
7
8
  const WINDIR = process.env.WINDIR || String.raw `C:\Windows`;
@@ -290,3 +291,58 @@ exports.ps = new PowerShellPool({ size: 4 });
290
291
  if (const_1.WINDOWS) {
291
292
  process.on('exit', () => exports.ps.stop());
292
293
  }
294
+ const parseWindowsLocationInfo = (value) => {
295
+ const text = String(value ?? '').trim();
296
+ if (!/pci/i.test(text)) {
297
+ return '';
298
+ }
299
+ const numbers = text.match(/\d+/g);
300
+ if (!numbers || numbers.length !== 3) {
301
+ return '';
302
+ }
303
+ const [bus, device, fn] = numbers.map((part) => parseInt(part, 10));
304
+ if ([bus, device, fn].some((part) => Number.isNaN(part))) {
305
+ return '';
306
+ }
307
+ return `${bus.toString(16).padStart(2, '0')}:${device.toString(16).padStart(2, '0')}.${fn.toString(16)}`;
308
+ };
309
+ exports.parseWindowsLocationInfo = parseWindowsLocationInfo;
310
+ const parseWindowsPnpLocations = (stdout) => {
311
+ const result = new Map();
312
+ for (const line of String(stdout ?? '').split('\n')) {
313
+ const separator = line.indexOf('|');
314
+ if (separator < 1) {
315
+ continue;
316
+ }
317
+ const busAddress = (0, exports.parseWindowsLocationInfo)(line.substring(separator + 1));
318
+ if (busAddress) {
319
+ result.set(line.substring(0, separator).trim().toLowerCase(), busAddress);
320
+ }
321
+ }
322
+ return result;
323
+ };
324
+ exports.parseWindowsPnpLocations = parseWindowsPnpLocations;
325
+ const matchPnpLocation = (deviceId, locations) => {
326
+ const id = String(deviceId ?? '').trim().toLowerCase();
327
+ if (!id) {
328
+ return '';
329
+ }
330
+ const exact = locations.get(id);
331
+ if (exact) {
332
+ return exact;
333
+ }
334
+ const candidates = [...locations].filter(([instanceId]) => instanceId.startsWith(`${id}\\`));
335
+ return candidates.length === 1 ? candidates[0][1] : '';
336
+ };
337
+ exports.matchPnpLocation = matchPnpLocation;
338
+ const PS_PNP_DISPLAY_LOCATIONS = 'Get-PnpDevice -Class Display -PresentOnly -ErrorAction SilentlyContinue | ForEach-Object { ' +
339
+ "$l = ($_ | Get-PnpDeviceProperty -KeyName DEVPKEY_Device_LocationInfo -ErrorAction SilentlyContinue).Data; \"$($_.InstanceId)|$l\" }";
340
+ const windowsPciBusAddresses = async () => {
341
+ try {
342
+ return (0, exports.parseWindowsPnpLocations)(await (0, exec_1.shareInflight)('pnpDisplayLocations', () => exports.ps.exec(PS_PNP_DISPLAY_LOCATIONS)));
343
+ }
344
+ catch {
345
+ return new Map();
346
+ }
347
+ };
348
+ exports.windowsPciBusAddresses = windowsPciBusAddresses;
@@ -1,2 +1,3 @@
1
1
  import { DisplayData } from '../common/types';
2
+ export declare const parseIoregPowerState: (stdout: string) => "" | "on" | "off" | "standby" | "suspend";
2
3
  export declare const displays: () => Promise<DisplayData[]>;
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displays = void 0;
3
+ exports.displays = exports.parseIoregPowerState = void 0;
4
4
  const common_1 = require("../common");
5
5
  const darwin_1 = require("../common/darwin");
6
6
  const exec_1 = require("../common/exec");
7
+ const EXEC_OPTS = { timeout: 5000 };
7
8
  const mappings_1 = require("../common/mappings");
8
9
  const parseDisplaysDarwin = (graphicsArr) => {
9
10
  const displays = [];
10
11
  try {
11
12
  graphicsArr.forEach((item) => {
12
13
  if (item.spdisplays_ndrvs && item.spdisplays_ndrvs.length) {
14
+ const gpu = item['sppci_model'] || item['_name'] || '';
13
15
  item.spdisplays_ndrvs.forEach((displayItem) => {
14
16
  const connectionType = displayItem['spdisplays_connection_type'] || '';
15
17
  const currentResolutionParts = (displayItem['_spdisplays_resolution'] || '').split('@');
@@ -42,6 +44,9 @@ const parseDisplaysDarwin = (graphicsArr) => {
42
44
  workAreaResolutionY: null,
43
45
  workAreaPositionX: null,
44
46
  workAreaPositionY: null,
47
+ powerState: '',
48
+ gpu,
49
+ gpuBusAddress: '',
45
50
  currentRefreshRate: currentResolutionParts.length > 1 ? parseInt(currentResolutionParts[1], 10) : null,
46
51
  scale: null
47
52
  });
@@ -116,6 +121,26 @@ const getWorkAreaDarwin = async (displays) => {
116
121
  catch { }
117
122
  return displays;
118
123
  };
124
+ const parseIoregPowerState = (stdout) => {
125
+ const match = stdout.match(/"MaxPowerState"=(\d+)[^}]*"CurrentPowerState"=(\d+)/);
126
+ if (!match) {
127
+ return '';
128
+ }
129
+ const max = (0, common_1.toInt)(match[1]);
130
+ const current = (0, common_1.toInt)(match[2]);
131
+ if (!max) {
132
+ return '';
133
+ }
134
+ if (current >= max) {
135
+ return 'on';
136
+ }
137
+ if (!current) {
138
+ return 'off';
139
+ }
140
+ return current === max - 1 ? 'standby' : 'suspend';
141
+ };
142
+ exports.parseIoregPowerState = parseIoregPowerState;
143
+ const getPowerStateDarwin = async () => (0, exports.parseIoregPowerState)(await (0, exec_1.execSecure)('ioreg', ['-n', 'IODisplayWrangler', '-r', '-d', '1'], EXEC_OPTS));
119
144
  const displays = async () => {
120
145
  await (0, common_1.nextTick)();
121
146
  let result = [];
@@ -124,6 +149,10 @@ const displays = async () => {
124
149
  result = parseDisplaysDarwin((0, darwin_1.plistParser)(stdout));
125
150
  result = await getDisplayPositionDarwin(result);
126
151
  result = await getWorkAreaDarwin(result);
152
+ const powerState = await getPowerStateDarwin();
153
+ for (const display of result) {
154
+ display.powerState = powerState;
155
+ }
127
156
  }
128
157
  catch { }
129
158
  return result;
@@ -40,6 +40,7 @@ export { pci } from './pci';
40
40
  export { printer } from './printer';
41
41
  export { processes } from '../linux/processes';
42
42
  export { processLoad } from '../linux/process-load';
43
+ export { processFocused } from './process-focused';
43
44
  export { services } from '../linux/services';
44
45
  export { shell } from '../shell';
45
46
  export { software } from './software';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
3
+ exports.services = exports.processFocused = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -92,6 +92,8 @@ var processes_1 = require("../linux/processes");
92
92
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
93
93
  var process_load_1 = require("../linux/process-load");
94
94
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
95
+ var process_focused_1 = require("./process-focused");
96
+ Object.defineProperty(exports, "processFocused", { enumerable: true, get: function () { return process_focused_1.processFocused; } });
95
97
  var services_1 = require("../linux/services");
96
98
  Object.defineProperty(exports, "services", { enumerable: true, get: function () { return services_1.services; } });
97
99
  var shell_1 = require("../shell");
@@ -7,6 +7,7 @@ const exec_1 = require("../common/exec");
7
7
  const network_1 = require("../common/network");
8
8
  const security_1 = require("../common/security");
9
9
  const darwin_1 = require("../darwin");
10
+ const EXEC_OPTS = { timeout: 5000 };
10
11
  const _network = {};
11
12
  const networkStatsSingle = async (iface) => {
12
13
  await (0, common_1.nextTick)();
@@ -19,11 +20,11 @@ const networkStatsSingle = async (iface) => {
19
20
  let rx_errors = 0;
20
21
  let tx_dropped = 0;
21
22
  let tx_errors = 0;
22
- let stdout = await (0, exec_1.execSecure)('ifconfig', [iface]);
23
+ let stdout = await (0, exec_1.execSecure)('ifconfig', [iface], EXEC_OPTS);
23
24
  const statusLine = stdout.split('\n').find((l) => l.includes('status')) || '';
24
25
  operstate = (statusLine.split(':')[1] || '').trim().toLowerCase();
25
26
  operstate = operstate === 'active' ? 'up' : operstate === 'inactive' ? 'down' : 'unknown';
26
- stdout = await (0, exec_1.execSecure)('netstat', ['-bdnI', iface]);
27
+ stdout = await (0, exec_1.execSecure)('netstat', ['-bdnI', iface], EXEC_OPTS);
27
28
  if (stdout) {
28
29
  const lines = stdout.toString().split('\n');
29
30
  if (lines.length > 1 && lines[1].trim() !== '') {
@@ -0,0 +1,3 @@
1
+ import type { ProcessFocusedData } from '../common/types';
2
+ export declare const parseLsappinfo: (stdout: string) => ProcessFocusedData | null;
3
+ export declare const processFocused: () => Promise<ProcessFocusedData | null>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFocused = exports.parseLsappinfo = void 0;
4
+ const common_1 = require("../common");
5
+ const exec_1 = require("../common/exec");
6
+ const EXEC_OPTS = { timeout: 5000 };
7
+ const parseLsappinfo = (stdout) => {
8
+ const pid = (0, common_1.toInt)((stdout.match(/pid\s*=\s*(\d+)/) || [])[1]);
9
+ if (!pid) {
10
+ return null;
11
+ }
12
+ return {
13
+ pid,
14
+ name: (stdout.match(/^"([^"]+)"/) || [])[1] || '',
15
+ path: (stdout.match(/executable path="([^"]+)"/) || [])[1] || ''
16
+ };
17
+ };
18
+ exports.parseLsappinfo = parseLsappinfo;
19
+ const processFocused = async () => {
20
+ const asn = (await (0, exec_1.execSecure)('lsappinfo', ['front'], EXEC_OPTS)).trim();
21
+ if (!/^ASN:0x[0-9a-f]+-0x[0-9a-f]+:$/i.test(asn)) {
22
+ return null;
23
+ }
24
+ return (0, exports.parseLsappinfo)(await (0, exec_1.execSecure)('lsappinfo', ['info', '-only', 'pid,name,executablepath', asn], EXEC_OPTS));
25
+ };
26
+ exports.processFocused = processFocused;
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { pci } from './pci';
44
44
  export { printer } from './printer';
45
45
  export { processes } from './processes';
46
46
  export { processLoad } from './process-load';
47
+ export { processFocused } from './process-focused';
47
48
  export { serialPorts } from './serial-ports';
48
49
  export { services } from './services';
49
50
  export { shell } from './shell';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.osInfo = exports.observe = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetPublicIp = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.getAllData = exports.getDynamicData = exports.getStaticData = exports.get = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.serialPorts = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.serialPorts = exports.processFocused = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -102,6 +102,8 @@ var processes_1 = require("./processes");
102
102
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
103
103
  var process_load_1 = require("./process-load");
104
104
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
105
+ var process_focused_1 = require("./process-focused");
106
+ Object.defineProperty(exports, "processFocused", { enumerable: true, get: function () { return process_focused_1.processFocused; } });
105
107
  var serial_ports_1 = require("./serial-ports");
106
108
  Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
107
109
  var services_1 = require("./services");
@@ -5,6 +5,7 @@ const exec_1 = require("../common/exec");
5
5
  const common_1 = require("../common");
6
6
  const filesys_1 = require("../common/filesys");
7
7
  const const_1 = require("../common/const");
8
+ const poolMatchLinux = async (data) => (0, filesys_1.applyPoolsLinux)(data, [...(await (0, filesys_1.zfsPoolsLinux)(data)), ...(await (0, filesys_1.btrfsPoolsLinux)(data))]);
8
9
  const blockDevices = async () => {
9
10
  await (0, common_1.nextTick)();
10
11
  let stdout = '';
@@ -13,6 +14,7 @@ const blockDevices = async () => {
13
14
  const lines = (0, filesys_1.blkStdoutToObject)(stdout).split('\n');
14
15
  let data = (0, filesys_1.parseLinuxBlk)(lines);
15
16
  data = await (0, filesys_1.raidMatchLinux)(data);
17
+ data = await poolMatchLinux(data);
16
18
  return (0, filesys_1.matchDevicesLinux)(data);
17
19
  }
18
20
  catch {
@@ -20,7 +22,7 @@ const blockDevices = async () => {
20
22
  ({ stdout } = await (0, exec_1.exec)('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', const_1.execOptsLinux));
21
23
  const lines = (0, filesys_1.blkStdoutToObject)(stdout).split('\n');
22
24
  const data = (0, filesys_1.parseLinuxBlk)(lines);
23
- return await (0, filesys_1.raidMatchLinux)(data);
25
+ return await poolMatchLinux(await (0, filesys_1.raidMatchLinux)(data));
24
26
  }
25
27
  catch {
26
28
  return [];
@@ -1,3 +1,10 @@
1
1
  import { DisplayData } from '../common/types';
2
+ export declare const dpmsToPowerState: (value: string) => "" | "on" | "off" | "standby" | "suspend";
3
+ export declare const normalizeDrmConnector: (name: string) => string;
4
+ export declare const parseDrmDevicePath: (target: string) => string;
5
+ export declare const drmConnectorInfo: (path?: string) => Promise<Map<string, {
6
+ powerState: string;
7
+ gpuBusAddress: string;
8
+ }>>;
2
9
  export declare const drmDisplays: (path?: string) => Promise<DisplayData[]>;
3
10
  export declare const displays: () => Promise<DisplayData[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displays = exports.drmDisplays = void 0;
3
+ exports.displays = exports.drmDisplays = exports.drmConnectorInfo = exports.parseDrmDevicePath = exports.normalizeDrmConnector = exports.dpmsToPowerState = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const node_path_1 = require("node:path");
6
6
  const common_1 = require("../common");
@@ -173,6 +173,59 @@ const getWorkAreaLinux = async (displays) => {
173
173
  catch { }
174
174
  return displays;
175
175
  };
176
+ const dpmsToPowerState = (value) => {
177
+ const state = value.trim().toLowerCase();
178
+ return state === 'on' || state === 'off' || state === 'standby' || state === 'suspend' ? state : '';
179
+ };
180
+ exports.dpmsToPowerState = dpmsToPowerState;
181
+ const normalizeDrmConnector = (name) => name.replace(/^card\d+-/, '').replace(/^(HDMI|DVI)-[AB]-/i, '$1-').toLowerCase();
182
+ exports.normalizeDrmConnector = normalizeDrmConnector;
183
+ const parseDrmDevicePath = (target) => {
184
+ const address = (target.split('/').pop() || '').replace(/^0000:/, '');
185
+ return /^[\da-f]{2}:[\da-f]{2}\.[\da-f]$/i.test(address) ? address : '';
186
+ };
187
+ exports.parseDrmDevicePath = parseDrmDevicePath;
188
+ const drmConnectorInfo = async (path = '/sys/class/drm') => {
189
+ const result = new Map();
190
+ let connectors = [];
191
+ try {
192
+ connectors = (await (0, promises_1.readdir)(path)).filter((name) => /^card\d+-/.test(name) && (0, security_1.isSafePathSegment)(name));
193
+ }
194
+ catch {
195
+ return result;
196
+ }
197
+ const busAddresses = new Map();
198
+ for (const connector of connectors) {
199
+ const card = connector.replace(/-.*$/, '');
200
+ if (!busAddresses.has(card)) {
201
+ busAddresses.set(card, (0, exports.parseDrmDevicePath)(await (0, promises_1.readlink)((0, node_path_1.join)(path, card, 'device')).catch(() => '')));
202
+ }
203
+ result.set((0, exports.normalizeDrmConnector)(connector), {
204
+ powerState: (0, exports.dpmsToPowerState)(await (0, files_1.readSysfs)((0, node_path_1.join)(path, connector, 'dpms'))),
205
+ gpuBusAddress: busAddresses.get(card) || ''
206
+ });
207
+ }
208
+ return result;
209
+ };
210
+ exports.drmConnectorInfo = drmConnectorInfo;
211
+ const applyDrmInfo = async (displays) => {
212
+ const info = await (0, exports.drmConnectorInfo)();
213
+ if (!info.size) {
214
+ return displays;
215
+ }
216
+ const single = (pick) => {
217
+ const values = new Set([...info.values()].map(pick).filter(Boolean));
218
+ return values.size === 1 ? [...values][0] : '';
219
+ };
220
+ const powerStateFallback = single((entry) => entry.powerState);
221
+ const busAddressFallback = single((entry) => entry.gpuBusAddress);
222
+ for (const display of displays) {
223
+ const entry = info.get((0, exports.normalizeDrmConnector)(display.connection || ''));
224
+ display.powerState = (entry && entry.powerState) || powerStateFallback;
225
+ display.gpuBusAddress = (entry && entry.gpuBusAddress) || busAddressFallback;
226
+ }
227
+ return displays;
228
+ };
176
229
  const drmDisplays = async (path = '/sys/class/drm') => {
177
230
  const result = [];
178
231
  let connectors = [];
@@ -229,6 +282,9 @@ const displays = async () => {
229
282
  const parts = lines[0].replace('mode', '').replace(/"/g, '').trim().split('x');
230
283
  if (parts.length === 2) {
231
284
  result.push({
285
+ powerState: '',
286
+ gpu: '',
287
+ gpuBusAddress: '',
232
288
  vendor: '',
233
289
  vendorId: null,
234
290
  model: (0, common_1.getValue)(lines, 'device_name', '='),
@@ -270,7 +326,7 @@ const displays = async () => {
270
326
  const lines = stdout.toString().split('\n');
271
327
  const xrandrDisplays = parseLinesLinuxDisplays(lines, depth);
272
328
  if (xrandrDisplays.length) {
273
- return await getWorkAreaLinux(xrandrDisplays);
329
+ return await applyDrmInfo(await getWorkAreaLinux(xrandrDisplays));
274
330
  }
275
331
  }
276
332
  catch { }
@@ -279,6 +335,6 @@ const displays = async () => {
279
335
  }
280
336
  catch { }
281
337
  const drm = await (0, exports.drmDisplays)();
282
- return drm.length ? drm : result;
338
+ return await applyDrmInfo(drm.length ? drm : result);
283
339
  };
284
340
  exports.displays = displays;
@@ -40,6 +40,7 @@ export { pci } from './pci';
40
40
  export { printer } from './printer';
41
41
  export { processes } from './processes';
42
42
  export { processLoad } from './process-load';
43
+ export { processFocused } from './process-focused';
43
44
  export { services } from './services';
44
45
  export { shell } from '../shell';
45
46
  export { software } from './software';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
3
+ exports.services = exports.processFocused = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -92,6 +92,8 @@ var processes_1 = require("./processes");
92
92
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
93
93
  var process_load_1 = require("./process-load");
94
94
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
95
+ var process_focused_1 = require("./process-focused");
96
+ Object.defineProperty(exports, "processFocused", { enumerable: true, get: function () { return process_focused_1.processFocused; } });
95
97
  var services_1 = require("./services");
96
98
  Object.defineProperty(exports, "services", { enumerable: true, get: function () { return services_1.services; } });
97
99
  var shell_1 = require("../shell");
@@ -14,6 +14,7 @@ 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
16
  const pci_1 = require("./pci");
17
+ const EXEC_OPTS = { timeout: 5000 };
17
18
  let _interfaces = {};
18
19
  let _networkInterfaces = [];
19
20
  const splitSectionsNics = (lines) => {
@@ -337,7 +338,7 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
337
338
  const [sysfsLines, wirelessLines, iwOut] = await Promise.all([
338
339
  (0, security_1.isSafePathSegment)(ifaceSanitized) ? (0, files_1.readSysfsMany)(`/sys/class/net/${ifaceSanitized}`, ['address', 'carrier_changes', 'duplex', 'mtu', 'operstate', 'speed', 'type']) : [],
339
340
  (0, files_1.readFileLines)('/proc/net/wireless'),
340
- (0, exec_1.execSecure)('iw', ['dev', ifaceSanitized, 'link'])
341
+ (0, exec_1.execSecure)('iw', ['dev', ifaceSanitized, 'link'], EXEC_OPTS)
341
342
  ]);
342
343
  lines = sysfsLines;
343
344
  lines.push(`wireless: ${wirelessLines.find((line) => line.indexOf(ifaceSanitized) >= 0) || ''}`);
@@ -0,0 +1,4 @@
1
+ import type { ProcessFocusedData } from '../common/types';
2
+ export declare const parseXpropWindowId: (stdout: string) => string;
3
+ export declare const parseXpropPid: (stdout: string) => number;
4
+ export declare const processFocused: () => Promise<ProcessFocusedData | null>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFocused = exports.parseXpropPid = exports.parseXpropWindowId = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const common_1 = require("../common");
6
+ const exec_1 = require("../common/exec");
7
+ const EXEC_OPTS = { timeout: 5000 };
8
+ const parseXpropWindowId = (stdout) => {
9
+ const id = (stdout.match(/window id # (0x[0-9a-f]+)/i) || [])[1] || '';
10
+ return Number(id) ? id : '';
11
+ };
12
+ exports.parseXpropWindowId = parseXpropWindowId;
13
+ const parseXpropPid = (stdout) => (0, common_1.toInt)((stdout.match(/_NET_WM_PID\(CARDINAL\) = (\d+)/) || [])[1]);
14
+ exports.parseXpropPid = parseXpropPid;
15
+ const activeWindowPid = async () => {
16
+ const pid = (0, common_1.toInt)(await (0, exec_1.execSecure)('xdotool', ['getactivewindow', 'getwindowpid'], EXEC_OPTS));
17
+ if (pid) {
18
+ return pid;
19
+ }
20
+ const windowId = (0, exports.parseXpropWindowId)(await (0, exec_1.execSecure)('xprop', ['-root', '_NET_ACTIVE_WINDOW'], EXEC_OPTS));
21
+ return windowId ? (0, exports.parseXpropPid)(await (0, exec_1.execSecure)('xprop', ['-id', windowId, '_NET_WM_PID'], EXEC_OPTS)) : 0;
22
+ };
23
+ const processFocused = async () => {
24
+ const pid = await activeWindowPid();
25
+ if (!pid) {
26
+ return null;
27
+ }
28
+ const path = await (0, promises_1.readlink)(`/proc/${pid}/exe`).catch(() => '');
29
+ const name = path ? path.split('/').pop() || '' : (await (0, promises_1.readFile)(`/proc/${pid}/comm`, 'utf8').catch(() => '')).trim();
30
+ return { pid, name, path };
31
+ };
32
+ exports.processFocused = processFocused;
@@ -7,6 +7,7 @@ const common_1 = require("../common");
7
7
  const security_1 = require("../common/security");
8
8
  const parse_1 = require("../common/parse");
9
9
  const files_1 = require("../common/files");
10
+ const EXEC_OPTS = { timeout: 5000 };
10
11
  const _process_cpu = {
11
12
  all: 0,
12
13
  all_utime: 0,
@@ -23,7 +24,7 @@ const processLoad = async (proc) => {
23
24
  const processes = (0, security_1.sanitizeServiceString)(proc);
24
25
  if (processes.length) {
25
26
  const args = ['-axo', 'pid,ppid,pcpu,pmem,comm'];
26
- stdout = await (0, exec_1.execSecure)('ps', args);
27
+ stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
27
28
  if (stdout) {
28
29
  const procStats = [];
29
30
  const lines = stdout.split('\n').filter((line) => {
@@ -7,6 +7,7 @@ const exec_1 = require("../common/exec");
7
7
  const files_1 = require("../common/files");
8
8
  const parse_1 = require("../common/parse");
9
9
  const security_1 = require("../common/security");
10
+ const EXEC_OPTS = { timeout: 5000 };
10
11
  const _services_cpu = {
11
12
  all: 0,
12
13
  all_utime: 0,
@@ -145,7 +146,7 @@ const systemdUnits = async () => {
145
146
  '--property=ActiveExitTimestamp',
146
147
  '--property=MainPID',
147
148
  '*.service'
148
- ]);
149
+ ], EXEC_OPTS);
149
150
  stdout.split(/\n\s*\n/).forEach((block) => {
150
151
  const lines = block.split('\n');
151
152
  const id = (0, common_1.getValue)(lines, 'Id', '=', false, true);
@@ -178,7 +179,7 @@ const elapsedToDate = (elapsed) => {
178
179
  };
179
180
  const psProcessesLinux = async () => {
180
181
  const procs = [];
181
- const stdout = await (0, exec_1.execSecure)('ps', ['-axo', 'pcpu,pmem,pid,ppid']);
182
+ const stdout = await (0, exec_1.execSecure)('ps', ['-axo', 'pcpu,pmem,pid,ppid'], EXEC_OPTS);
182
183
  stdout
183
184
  .replace(/ +/g, ' ')
184
185
  .replace(/,+/g, '.')
@@ -257,7 +258,7 @@ const services = async (srv) => {
257
258
  }
258
259
  let args = const_1.DARWIN ? ['-caxo', 'pcpu,pmem,pid,etime,command'] : ['-axo', 'pcpu,pmem,pid,etime,command'];
259
260
  if (srvs.length > 0) {
260
- let stdout = await (0, exec_1.execSecure)('ps', args);
261
+ let stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
261
262
  if (stdout) {
262
263
  const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
263
264
  srvs.forEach((srv) => {
@@ -313,7 +314,7 @@ const services = async (srv) => {
313
314
  }
314
315
  else {
315
316
  args = ['-o', 'comm'];
316
- stdout = await (0, exec_1.execSecure)('ps', args);
317
+ stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
317
318
  if (stdout) {
318
319
  const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
319
320
  srvs.forEach((srv) => {
@@ -0,0 +1 @@
1
+ export declare const processFocused: () => Promise<import("./common/types").ProcessFocusedData | null>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFocused = void 0;
4
+ const const_1 = require("./common/const");
5
+ const processFocused = async () => {
6
+ switch (true) {
7
+ case const_1.LINUX:
8
+ return (await import('./linux/process-focused.js')).processFocused();
9
+ case const_1.DARWIN:
10
+ return (await import('./darwin/process-focused.js')).processFocused();
11
+ case const_1.WINDOWS:
12
+ return (await import('./windows/process-focused.js')).processFocused();
13
+ default:
14
+ return null;
15
+ }
16
+ };
17
+ exports.processFocused = processFocused;
@@ -1,2 +1,7 @@
1
1
  import type { DisplayData } from '../common/types';
2
+ export declare const parseEnumDisplayDevices: (stdout: any) => Map<string, {
3
+ gpu: string;
4
+ deviceId: string;
5
+ }>;
6
+ export declare const windowsAvailabilityToPowerState: (value: string) => string;
2
7
  export declare const displays: () => Promise<DisplayData[]>;
@@ -1,12 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displays = void 0;
3
+ exports.displays = exports.windowsAvailabilityToPowerState = exports.parseEnumDisplayDevices = void 0;
4
4
  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
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
- const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, connections, isections, currentModes) => {
9
+ const psDisplayAdapters = `if (-not ([System.Management.Automation.PSTypeName]'SIDispHolder').Type) { Add-Type -TypeDefinition @"
10
+ using System;
11
+ using System.Runtime.InteropServices;
12
+ public class SIDispHolder {
13
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
14
+ public struct DISPLAY_DEVICE {
15
+ public int cb;
16
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string DeviceName;
17
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)] public string DeviceString;
18
+ public int StateFlags;
19
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)] public string DeviceID;
20
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)] public string DeviceKey;
21
+ }
22
+ [DllImport("user32.dll", CharSet=CharSet.Unicode)]
23
+ public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref SIDispHolder.DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
24
+ }
25
+ "@ -ErrorAction SilentlyContinue };
26
+ $d = New-Object SIDispHolder+DISPLAY_DEVICE;
27
+ for ($i = 0; $i -lt 16; $i++) {
28
+ $d.cb = [System.Runtime.InteropServices.Marshal]::SizeOf($d);
29
+ if (-not [SIDispHolder]::EnumDisplayDevices($null, $i, [ref]$d, 0)) { break };
30
+ "$($d.DeviceName)|$($d.DeviceString)|$($d.DeviceID)"
31
+ }`;
32
+ const parseEnumDisplayDevices = (stdout) => {
33
+ const result = new Map();
34
+ for (const line of String(stdout ?? '').split('\n')) {
35
+ const parts = line.trim().split('|');
36
+ if (parts.length < 3 || !parts[0].startsWith('\\\\.\\')) {
37
+ continue;
38
+ }
39
+ result.set(parts[0].toLowerCase(), { gpu: parts[1].trim(), deviceId: parts[2].trim() });
40
+ }
41
+ return result;
42
+ };
43
+ exports.parseEnumDisplayDevices = parseEnumDisplayDevices;
44
+ const WIN_AVAILABILITY = new Map([
45
+ ['3', 'on'],
46
+ ['7', 'off'],
47
+ ['8', 'off'],
48
+ ['13', 'standby'],
49
+ ['14', 'standby'],
50
+ ['15', 'standby'],
51
+ ['17', 'standby']
52
+ ]);
53
+ const windowsAvailabilityToPowerState = (value) => WIN_AVAILABILITY.get(String(value ?? '').trim()) || '';
54
+ exports.windowsAvailabilityToPowerState = windowsAvailabilityToPowerState;
55
+ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, connections, isections, currentModes, adapters, locations) => {
10
56
  const displays = [];
11
57
  const desktopMonitors = (dsections || []).map((section) => {
12
58
  const linesDisplay = section.split('\n');
@@ -15,7 +61,8 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
15
61
  vendor: (0, common_1.getValue)(linesDisplay, 'MonitorManufacturer', ':'),
16
62
  model: (0, common_1.getValue)(linesDisplay, 'Name', ':'),
17
63
  resolutionX: (0, common_1.toInt)((0, common_1.getValue)(linesDisplay, 'ScreenWidth', ':')),
18
- resolutionY: (0, common_1.toInt)((0, common_1.getValue)(linesDisplay, 'ScreenHeight', ':'))
64
+ resolutionY: (0, common_1.toInt)((0, common_1.getValue)(linesDisplay, 'ScreenHeight', ':')),
65
+ powerState: (0, exports.windowsAvailabilityToPowerState)((0, common_1.getValue)(linesDisplay, 'Availability', ':'))
19
66
  };
20
67
  });
21
68
  const count = Math.max(ssections.length, monitors.length);
@@ -74,13 +121,19 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
74
121
  workAreaPositionX: workAreaWidth ? Math.round(posX + ((0, common_1.toInt)((0, common_1.getValue)(workArea, 'X', ':')) - boundsX) * dpiScale) : null,
75
122
  workAreaPositionY: workAreaHeight ? Math.round(posY + ((0, common_1.toInt)((0, common_1.getValue)(workArea, 'Y', ':')) - boundsY) * dpiScale) : null,
76
123
  currentRefreshRate: (mode && mode.refreshRate) || null,
77
- scale: mode && boundsWidth ? Math.round((mode.width / boundsWidth) * 100) / 100 : null
124
+ scale: mode && boundsWidth ? Math.round((mode.width / boundsWidth) * 100) / 100 : null,
125
+ powerState: dsection ? dsection.powerState : '',
126
+ gpu: adapters.get(deviceName.toLowerCase())?.gpu || '',
127
+ gpuBusAddress: (0, windows_1.matchPnpLocation)(adapters.get(deviceName.toLowerCase())?.deviceId || '', locations)
78
128
  });
79
129
  }
80
130
  }
81
131
  if (ssections.length === 0) {
82
132
  const first = desktopMonitors[0];
83
133
  displays.push({
134
+ powerState: first ? first.powerState : '',
135
+ gpu: [...adapters.values()][0]?.gpu || '',
136
+ gpuBusAddress: (0, windows_1.matchPnpLocation)([...adapters.values()][0]?.deviceId || '', locations),
84
137
  vendor: first ? first.vendor : '',
85
138
  vendorId: null,
86
139
  model: first ? first.model : '',
@@ -123,6 +176,7 @@ const displays = async () => {
123
176
  workload.push(windows_1.ps.exec('Get-CimInstance -Namespace root\\wmi -ClassName WmiMonitorConnectionParams | fl'));
124
177
  workload.push(windows_1.ps.exec('gwmi WmiMonitorID -Namespace root\\wmi | ForEach-Object {(($_.ManufacturerName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.ProductCodeID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.UserFriendlyName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.SerialNumberID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + $_.YearOfManufacture + "|" + $_.InstanceName}'));
125
178
  workload.push(windows_1.ps.exec(psCurrentModes));
179
+ workload.push(windows_1.ps.exec(psDisplayAdapters));
126
180
  const data = await Promise.allSettled(workload).then((results) => results.map((result) => (result.status === 'fulfilled' ? result.value : '')));
127
181
  let _resolutionX = 0;
128
182
  let _resolutionY = 0;
@@ -213,7 +267,7 @@ const displays = async () => {
213
267
  };
214
268
  }
215
269
  });
216
- result = parseLinesWindowsDisplaysPowershell(ssections, monitors, dsections, connections, isections, currentModes);
270
+ result = parseLinesWindowsDisplaysPowershell(ssections, monitors, dsections, connections, isections, currentModes, (0, exports.parseEnumDisplayDevices)(data[7]), await (0, windows_1.windowsPciBusAddresses)());
217
271
  if (result.length === 1) {
218
272
  if (_resolutionX) {
219
273
  result[0].resolutionX = _resolutionX;
@@ -5,7 +5,7 @@ const common_1 = require("../common");
5
5
  const nvidia_1 = require("../common/nvidia");
6
6
  const exec_1 = require("../common/exec");
7
7
  const windows_1 = require("../common/windows");
8
- const parseLinesWindowsControllers = (sections, vections) => {
8
+ const parseLinesWindowsControllers = (sections, vections, locations) => {
9
9
  const memorySizes = {};
10
10
  for (const i in vections) {
11
11
  if (Object.prototype.hasOwnProperty.call(vections, i)) {
@@ -70,6 +70,7 @@ const parseLinesWindowsControllers = (sections, vections) => {
70
70
  vendor: (0, common_1.getValue)(lines, 'AdapterCompatibility', ':'),
71
71
  model: (0, common_1.getValue)(lines, 'name', ':'),
72
72
  bus: (0, common_1.getValue)(lines, 'PNPDeviceID', ':').startsWith('PCI') ? 'PCI' : '',
73
+ busAddress: (0, windows_1.matchPnpLocation)((0, common_1.getValue)(lines, 'PNPDeviceID', ':'), locations),
73
74
  vram: (memorySize == null ? (0, common_1.toInt)((0, common_1.getValue)(lines, 'AdapterRAM', ':')) : memorySize) / 1024 / 1024,
74
75
  vramDynamic: (0, common_1.getValue)(lines, 'VideoMemoryType', ':') === '2',
75
76
  subDeviceId
@@ -96,7 +97,7 @@ const gpu = async () => {
96
97
  .toString()
97
98
  .replace(/\r/g, '')
98
99
  .split(/\n\s*\n/);
99
- result = parseLinesWindowsControllers(csections, vsections);
100
+ result = parseLinesWindowsControllers(csections, vsections, await (0, windows_1.windowsPciBusAddresses)());
100
101
  result = result.map((controller) => {
101
102
  if (controller.vendor.toLowerCase() === 'nvidia') {
102
103
  return (0, nvidia_1.mergeControllerNvidia)(controller, nvidiaData.find((device) => {
@@ -43,6 +43,7 @@ export { osInfo } from './os-info';
43
43
  export { pci } from './pci';
44
44
  export { printer } from './printer';
45
45
  export { processLoad } from './process-load';
46
+ export { processFocused } from './process-focused';
46
47
  export { processes } from './processes';
47
48
  export { services } from './services';
48
49
  export { shell } from './shell';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.gpu = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.displays = exports.disksIO = exports.diskLayout = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = exports.vboxInfo = exports.versions = exports.version = exports.time = exports.inetChecksite = exports.dockerVolumes = exports.dockerInfo = exports.dockerImages = exports.dockerContainerStats = exports.dockerContainers = exports.dockerContainerProcesses = exports.dockerAll = exports.fullLoad = exports.cpuCurrentSpeed = exports.currentLoad = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = exports.processLoad = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = exports.processFocused = exports.processLoad = void 0;
5
5
  var cpu_current_load_1 = require("../cpu-current-load");
6
6
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
7
7
  var cpu_current_speed_1 = require("../cpu-current-speed");
@@ -98,6 +98,8 @@ var printer_1 = require("./printer");
98
98
  Object.defineProperty(exports, "printer", { enumerable: true, get: function () { return printer_1.printer; } });
99
99
  var process_load_1 = require("./process-load");
100
100
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
101
+ var process_focused_1 = require("./process-focused");
102
+ Object.defineProperty(exports, "processFocused", { enumerable: true, get: function () { return process_focused_1.processFocused; } });
101
103
  var processes_1 = require("./processes");
102
104
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
103
105
  var services_1 = require("./services");
@@ -0,0 +1,3 @@
1
+ import type { ProcessFocusedData } from '../common/types';
2
+ export declare const parseWindowsFocused: (data: any) => ProcessFocusedData | null;
3
+ export declare const processFocused: () => Promise<ProcessFocusedData | null>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFocused = exports.parseWindowsFocused = void 0;
4
+ const windows_1 = require("../common/windows");
5
+ const WIN_FOREGROUND = `if (-not ([System.Management.Automation.PSTypeName]'SI.Win').Type) { Add-Type -Namespace SI -Name Win -MemberDefinition '` +
6
+ '[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); ' +
7
+ '[DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);' +
8
+ `' }; ` +
9
+ '$p = 0; [void][SI.Win]::GetWindowThreadProcessId([SI.Win]::GetForegroundWindow(), [ref]$p); ' +
10
+ '$proc = Get-Process -Id $p -ErrorAction SilentlyContinue; ' +
11
+ '[PSCustomObject]@{pid=$p;name=$proc.ProcessName;path=$proc.Path} | ConvertTo-Json -compress';
12
+ const parseWindowsFocused = (data) => {
13
+ let parsed = data;
14
+ if (typeof parsed === 'string') {
15
+ try {
16
+ parsed = JSON.parse(parsed);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ if (!parsed || !parsed.pid) {
23
+ return null;
24
+ }
25
+ return { pid: parsed.pid, name: parsed.name || '', path: parsed.path || '' };
26
+ };
27
+ exports.parseWindowsFocused = parseWindowsFocused;
28
+ const processFocused = async () => {
29
+ try {
30
+ return (0, exports.parseWindowsFocused)(await windows_1.ps.exec(WIN_FOREGROUND));
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ };
36
+ exports.processFocused = processFocused;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.12",
3
+ "version": "6.0.0-beta.13",
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)",