systeminformation 6.0.0-beta.2 → 6.0.0-beta.21

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.
Files changed (139) hide show
  1. package/README.md +67 -18
  2. package/dist/bsd/mem.js +8 -3
  3. package/dist/bsd/network-stats.d.ts +1 -1
  4. package/dist/bsd/network-stats.js +14 -7
  5. package/dist/bsd/os-info.d.ts +1 -0
  6. package/dist/common/darwin.d.ts +2 -0
  7. package/dist/common/darwin.js +17 -1
  8. package/dist/common/defaults.d.ts +2 -1
  9. package/dist/common/defaults.js +36 -6
  10. package/dist/common/exec.js +29 -13
  11. package/dist/common/files.d.ts +9 -0
  12. package/dist/common/files.js +67 -3
  13. package/dist/common/filesys.d.ts +30 -0
  14. package/dist/common/filesys.js +228 -11
  15. package/dist/common/host.js +55 -3
  16. package/dist/common/internet.js +31 -20
  17. package/dist/common/mappings.d.ts +0 -3
  18. package/dist/common/mappings.js +35 -14
  19. package/dist/common/network.d.ts +15 -2
  20. package/dist/common/network.js +18 -22
  21. package/dist/common/nvidia.d.ts +1 -1
  22. package/dist/common/nvidia.js +4 -5
  23. package/dist/common/parse.d.ts +4 -6
  24. package/dist/common/parse.js +24 -69
  25. package/dist/common/security.d.ts +2 -0
  26. package/dist/common/security.js +18 -3
  27. package/dist/common/types.d.ts +53 -5
  28. package/dist/common/windows.d.ts +4 -0
  29. package/dist/common/windows.js +57 -1
  30. package/dist/cpu-current-load.d.ts +1 -0
  31. package/dist/cpu-current-load.js +54 -8
  32. package/dist/cpu-current-speed.js +5 -3
  33. package/dist/darwin/battery.d.ts +1 -1
  34. package/dist/darwin/battery.js +15 -5
  35. package/dist/darwin/camera.js +3 -3
  36. package/dist/darwin/disk-layout.js +16 -12
  37. package/dist/darwin/disks-io.js +3 -3
  38. package/dist/darwin/displays.d.ts +1 -0
  39. package/dist/darwin/displays.js +64 -2
  40. package/dist/darwin/fans.d.ts +2 -0
  41. package/dist/darwin/fans.js +28 -0
  42. package/dist/darwin/gpu.js +1 -1
  43. package/dist/darwin/index.d.ts +3 -0
  44. package/dist/darwin/index.js +8 -2
  45. package/dist/darwin/keyboard.js +4 -4
  46. package/dist/darwin/mouse.js +4 -4
  47. package/dist/darwin/network-interfaces.d.ts +3 -0
  48. package/dist/darwin/network-interfaces.js +81 -14
  49. package/dist/darwin/network-stats.d.ts +1 -1
  50. package/dist/darwin/network-stats.js +14 -7
  51. package/dist/darwin/os-info.d.ts +2 -0
  52. package/dist/darwin/os-info.js +24 -2
  53. package/dist/darwin/process-focused.d.ts +3 -0
  54. package/dist/darwin/process-focused.js +26 -0
  55. package/dist/darwin/serial-ports.d.ts +2 -0
  56. package/dist/darwin/serial-ports.js +94 -0
  57. package/dist/darwin/users.js +1 -1
  58. package/dist/docker.js +4 -5
  59. package/dist/fans.d.ts +1 -0
  60. package/dist/fans.js +17 -0
  61. package/dist/get-data.d.ts +4 -0
  62. package/dist/get-data.js +6 -2
  63. package/dist/get.js +6 -1
  64. package/dist/index.d.ts +3 -0
  65. package/dist/index.js +8 -2
  66. package/dist/inet-public-ip.js +2 -1
  67. package/dist/linux/audio.js +59 -0
  68. package/dist/linux/baseboard.js +9 -20
  69. package/dist/linux/bios.js +6 -15
  70. package/dist/linux/block-devices.js +3 -1
  71. package/dist/linux/camera.js +2 -1
  72. package/dist/linux/chassis.js +4 -10
  73. package/dist/linux/cpu-temperature.js +34 -19
  74. package/dist/linux/cpu.js +3 -1
  75. package/dist/linux/disk-layout.js +9 -12
  76. package/dist/linux/disks-io.js +9 -9
  77. package/dist/linux/displays.d.ts +8 -0
  78. package/dist/linux/displays.js +151 -4
  79. package/dist/linux/fans.d.ts +2 -0
  80. package/dist/linux/fans.js +92 -0
  81. package/dist/linux/fs-size.d.ts +1 -1
  82. package/dist/linux/fs-size.js +164 -37
  83. package/dist/linux/fs-stats.js +6 -9
  84. package/dist/linux/gpu.d.ts +2 -0
  85. package/dist/linux/gpu.js +97 -22
  86. package/dist/linux/index.d.ts +3 -0
  87. package/dist/linux/index.js +8 -2
  88. package/dist/linux/mem-layout.js +3 -7
  89. package/dist/linux/mem.d.ts +1 -0
  90. package/dist/linux/mem.js +21 -1
  91. package/dist/linux/network-interfaces.d.ts +1 -0
  92. package/dist/linux/network-interfaces.js +154 -113
  93. package/dist/linux/network-stats.d.ts +1 -1
  94. package/dist/linux/network-stats.js +14 -40
  95. package/dist/linux/npu.js +2 -1
  96. package/dist/linux/os-info.js +56 -5
  97. package/dist/linux/printer.js +4 -4
  98. package/dist/linux/process-focused.d.ts +4 -0
  99. package/dist/linux/process-focused.js +32 -0
  100. package/dist/linux/process-load.js +11 -13
  101. package/dist/linux/processes.js +89 -80
  102. package/dist/linux/serial-ports.d.ts +2 -0
  103. package/dist/linux/serial-ports.js +102 -0
  104. package/dist/linux/services.js +182 -49
  105. package/dist/linux/system.js +1 -7
  106. package/dist/linux/users.js +1 -1
  107. package/dist/linux/uuid.js +4 -10
  108. package/dist/linux/wifi-networks.js +2 -2
  109. package/dist/network-interfaces.js +1 -1
  110. package/dist/observe.d.ts +1 -1
  111. package/dist/observe.js +5 -1
  112. package/dist/process-focused.d.ts +1 -0
  113. package/dist/process-focused.js +17 -0
  114. package/dist/serial-ports.d.ts +1 -0
  115. package/dist/serial-ports.js +17 -0
  116. package/dist/versions.js +34 -80
  117. package/dist/windows/audio.d.ts +29 -0
  118. package/dist/windows/audio.js +151 -11
  119. package/dist/windows/disk-layout.js +3 -0
  120. package/dist/windows/disks-io.js +3 -3
  121. package/dist/windows/displays.d.ts +5 -0
  122. package/dist/windows/displays.js +101 -16
  123. package/dist/windows/fans.d.ts +2 -0
  124. package/dist/windows/fans.js +71 -0
  125. package/dist/windows/fs-size.js +1 -4
  126. package/dist/windows/gpu.js +3 -2
  127. package/dist/windows/index.d.ts +3 -0
  128. package/dist/windows/index.js +8 -2
  129. package/dist/windows/network-interfaces.js +36 -41
  130. package/dist/windows/network-stats.js +20 -6
  131. package/dist/windows/process-focused.d.ts +3 -0
  132. package/dist/windows/process-focused.js +36 -0
  133. package/dist/windows/process-load.js +7 -5
  134. package/dist/windows/processes.d.ts +1 -0
  135. package/dist/windows/processes.js +54 -26
  136. package/dist/windows/serial-ports.d.ts +3 -0
  137. package/dist/windows/serial-ports.js +73 -0
  138. package/dist/windows/services.js +4 -1
  139. package/package.json +1 -1
@@ -4,8 +4,10 @@ exports.services = void 0;
4
4
  const common_1 = require("../common");
5
5
  const const_1 = require("../common/const");
6
6
  const exec_1 = require("../common/exec");
7
+ const files_1 = require("../common/files");
7
8
  const parse_1 = require("../common/parse");
8
9
  const security_1 = require("../common/security");
10
+ const EXEC_OPTS = { timeout: 5000 };
9
11
  const _services_cpu = {
10
12
  all: 0,
11
13
  all_utime: 0,
@@ -82,17 +84,181 @@ const darwinGetServices = async () => {
82
84
  catch { }
83
85
  return srvs;
84
86
  };
87
+ const calcServicesCpuLinux = async (result) => {
88
+ result.forEach((item) => {
89
+ item.cpu = 0;
90
+ });
91
+ const pids = [];
92
+ for (const i in result) {
93
+ pids.push(...result[i].pids);
94
+ }
95
+ const cpuBaseline = { ..._services_cpu };
96
+ const stats = await (0, files_1.readProcStats)(pids);
97
+ const all = (0, parse_1.parseProcStat)(stats.all);
98
+ const curr_processes = stats.procs;
99
+ const list_new = {};
100
+ curr_processes.forEach((element) => {
101
+ const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, cpuBaseline);
102
+ if (resultProcess.pid) {
103
+ let listPos = -1;
104
+ for (let i = 0; i < result.length; i++) {
105
+ for (let j = 0; j < result[i].pids.length; j++) {
106
+ if (result[i].pids[j] === resultProcess.pid) {
107
+ listPos = i;
108
+ }
109
+ }
110
+ }
111
+ if (listPos >= 0) {
112
+ result[listPos].cpu += resultProcess.cpuu + resultProcess.cpus;
113
+ }
114
+ list_new[resultProcess.pid] = {
115
+ cpuu: resultProcess.cpuu,
116
+ cpus: resultProcess.cpus,
117
+ utime: resultProcess.utime,
118
+ stime: resultProcess.stime
119
+ };
120
+ }
121
+ });
122
+ _services_cpu.all = all;
123
+ _services_cpu.list = Object.assign({}, list_new);
124
+ _services_cpu.ms = Date.now();
125
+ _services_cpu.result = Object.assign({}, result);
126
+ };
127
+ const systemdTimestamp = (value) => {
128
+ const parts = value.match(/(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(?: (\S+))?/);
129
+ if (!parts) {
130
+ return null;
131
+ }
132
+ const utc = parts[3] === 'UTC' || parts[3] === 'GMT';
133
+ const date = new Date(`${parts[1]}T${parts[2]}${utc ? 'Z' : ''}`);
134
+ return Number.isNaN(date.getTime()) ? null : date;
135
+ };
136
+ const systemdUnits = async () => {
137
+ const units = [];
138
+ const stdout = await (0, exec_1.execSecure)('systemctl', [
139
+ 'show',
140
+ '--no-pager',
141
+ '--property=Id',
142
+ '--property=LoadState',
143
+ '--property=ActiveState',
144
+ '--property=UnitFileState',
145
+ '--property=ActiveEnterTimestamp',
146
+ '--property=ActiveExitTimestamp',
147
+ '--property=MainPID',
148
+ '*.service'
149
+ ], EXEC_OPTS);
150
+ stdout.split(/\n\s*\n/).forEach((block) => {
151
+ const lines = block.split('\n');
152
+ const id = (0, common_1.getValue)(lines, 'Id', '=', false, true);
153
+ if (id && (0, common_1.getValue)(lines, 'LoadState', '=', false, true) !== 'not-found') {
154
+ const mainPid = (0, common_1.toInt)((0, common_1.getValue)(lines, 'MainPID', '=', false, true));
155
+ const activeState = (0, common_1.getValue)(lines, 'ActiveState', '=', false, true);
156
+ const running = activeState === 'active' || activeState === 'reloading';
157
+ const enter = systemdTimestamp((0, common_1.getValue)(lines, 'ActiveEnterTimestamp', '=', false, true));
158
+ const exit = systemdTimestamp((0, common_1.getValue)(lines, 'ActiveExitTimestamp', '=', false, true));
159
+ units.push({
160
+ name: id.replace(/\.service$/, ''),
161
+ running,
162
+ startmode: (0, common_1.getValue)(lines, 'UnitFileState', '=', false, true),
163
+ lastChanged: (running ? enter || exit : exit || enter) || null,
164
+ mainPid
165
+ });
166
+ }
167
+ });
168
+ return units;
169
+ };
170
+ const elapsedToDate = (elapsed) => {
171
+ const parts = elapsed.split('-');
172
+ const days = parts.length > 1 ? (0, common_1.toInt)(parts[0]) : 0;
173
+ const time = (parts.length > 1 ? parts[1] : parts[0]).split(':');
174
+ if (time.length < 2 || time.length > 3) {
175
+ return null;
176
+ }
177
+ const seconds = time.reduce((total, part) => total * 60 + (0, common_1.toInt)(part), 0) + days * 86400;
178
+ return seconds > 0 ? new Date(Date.now() - seconds * 1000) : null;
179
+ };
180
+ const psProcessesLinux = async () => {
181
+ const procs = [];
182
+ const stdout = await (0, exec_1.execSecure)('ps', ['-axo', 'pcpu,pmem,pid,ppid'], EXEC_OPTS);
183
+ stdout
184
+ .replace(/ +/g, ' ')
185
+ .replace(/,+/g, '.')
186
+ .split('\n')
187
+ .forEach((line) => {
188
+ const parts = line.trim().split(' ');
189
+ if (parts.length >= 4) {
190
+ const pid = (0, common_1.toInt)(parts[2]);
191
+ if (pid) {
192
+ procs.push({ pid, ppid: (0, common_1.toInt)(parts[3]), cpu: parseFloat(parts[0]) || 0, mem: parseFloat(parts[1]) || 0 });
193
+ }
194
+ }
195
+ });
196
+ return procs;
197
+ };
198
+ const servicesFromSystemd = async (srvs, units) => {
199
+ const all = srvs.length === 1 && srvs[0] === '*';
200
+ const matches = (unit) => {
201
+ const name = unit.name.toLowerCase();
202
+ return srvs.indexOf(name) >= 0 || srvs.indexOf(`${name}.service`) >= 0;
203
+ };
204
+ const selected = all ? units : units.filter(matches);
205
+ const procs = await psProcessesLinux();
206
+ const byPid = {};
207
+ const children = {};
208
+ procs.forEach((proc) => {
209
+ byPid[proc.pid] = { cpu: proc.cpu, mem: proc.mem };
210
+ children[proc.ppid] = (children[proc.ppid] || []).concat(proc.pid);
211
+ });
212
+ const result = [];
213
+ selected.forEach((unit) => {
214
+ const pids = [];
215
+ const collect = (pid) => {
216
+ pids.push(pid);
217
+ (children[pid] || []).forEach(collect);
218
+ };
219
+ if (unit.mainPid && byPid[unit.mainPid]) {
220
+ collect(unit.mainPid);
221
+ }
222
+ result.push({
223
+ name: unit.name,
224
+ running: unit.running,
225
+ startmode: unit.startmode,
226
+ lastChanged: unit.lastChanged,
227
+ pids,
228
+ cpu: parseFloat(pids.reduce((sum, pid) => sum + (byPid[pid] ? byPid[pid].cpu : 0), 0).toFixed(2)),
229
+ mem: parseFloat(pids.reduce((sum, pid) => sum + (byPid[pid] ? byPid[pid].mem : 0), 0).toFixed(2))
230
+ });
231
+ });
232
+ if (!all) {
233
+ srvs
234
+ .filter((srv) => !selected.some((unit) => unit.name.toLowerCase() === srv || `${unit.name.toLowerCase()}.service` === srv))
235
+ .forEach((srv) => {
236
+ result.push({ name: srv, running: false, startmode: '', lastChanged: null, pids: [], cpu: 0, mem: 0 });
237
+ });
238
+ }
239
+ await calcServicesCpuLinux(result);
240
+ return result;
241
+ };
85
242
  const services = async (srv) => {
86
243
  await (0, common_1.nextTick)();
87
244
  const result = [];
88
245
  if (!(0, security_1.isPrototypePolluted)()) {
89
246
  let srvs = (0, security_1.sanitizeServiceString)(srv);
247
+ if (const_1.LINUX) {
248
+ try {
249
+ const units = await systemdUnits();
250
+ if (units.length) {
251
+ return await servicesFromSystemd(srvs, units);
252
+ }
253
+ }
254
+ catch { }
255
+ }
90
256
  if (srvs.length === 1 && srvs[0] === '*') {
91
257
  srvs = const_1.DARWIN ? await darwinGetServices() : await nixGetServices();
92
258
  }
93
- let args = const_1.DARWIN ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
259
+ let args = const_1.DARWIN ? ['-caxo', 'pcpu,pmem,pid,etime,command'] : ['-axo', 'pcpu,pmem,pid,etime,command'];
94
260
  if (srvs.length > 0) {
95
- let stdout = await (0, exec_1.execSecure)('ps', args);
261
+ let stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
96
262
  if (stdout) {
97
263
  const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
98
264
  srvs.forEach((srv) => {
@@ -112,16 +278,22 @@ const services = async (srv) => {
112
278
  });
113
279
  }
114
280
  const pids = [];
281
+ let lastChanged = null;
115
282
  for (const p of ps) {
116
- const pid = p.trim().split(' ')[2];
117
- if (pid) {
118
- pids.push((0, common_1.toInt)(pid));
283
+ const parts = p.trim().split(' ');
284
+ if (parts[2]) {
285
+ pids.push((0, common_1.toInt)(parts[2]));
286
+ const started = elapsedToDate(parts[3] || '');
287
+ if (started && (!lastChanged || started < lastChanged)) {
288
+ lastChanged = started;
289
+ }
119
290
  }
120
291
  }
121
292
  result.push({
122
293
  name: srv,
123
294
  running: ps.length > 0,
124
295
  startmode: '',
296
+ lastChanged,
125
297
  pids: pids,
126
298
  cpu: parseFloat(ps
127
299
  .reduce(function (pv, cv) {
@@ -136,54 +308,13 @@ const services = async (srv) => {
136
308
  });
137
309
  });
138
310
  if (const_1.LINUX) {
139
- let cmd = 'cat /proc/stat | grep "cpu "';
140
- for (const i in result) {
141
- for (const j in result[i].pids) {
142
- cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
143
- }
144
- }
145
- const { stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux);
146
- let curr_processes = stdout.toString().split('\n');
147
- const all = (0, parse_1.parseProcStat)(curr_processes[0]);
148
- curr_processes = curr_processes.slice(1);
149
- const list_new = {};
150
- curr_processes.forEach((element) => {
151
- const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, _services_cpu);
152
- if (resultProcess.pid) {
153
- let listPos = -1;
154
- for (let i = 0; i < result.length; i++) {
155
- for (let j = 0; j < result[i].pids.length; j++) {
156
- if (result[i].pids[j] === resultProcess.pid) {
157
- listPos = i;
158
- }
159
- }
160
- }
161
- if (listPos >= 0) {
162
- result[listPos].cpu += resultProcess.cpuu + resultProcess.cpus;
163
- }
164
- list_new[resultProcess.pid] = {
165
- cpuu: resultProcess.cpuu,
166
- cpus: resultProcess.cpus,
167
- utime: resultProcess.utime,
168
- stime: resultProcess.stime,
169
- cutime: resultProcess.cutime,
170
- cstime: resultProcess.cstime
171
- };
172
- }
173
- });
174
- _services_cpu.all = all;
175
- _services_cpu.list = Object.assign({}, list_new);
176
- _services_cpu.ms = Date.now();
177
- _services_cpu.result = Object.assign({}, result);
178
- return result;
179
- }
180
- else {
181
- return result;
311
+ await calcServicesCpuLinux(result);
182
312
  }
313
+ return result;
183
314
  }
184
315
  else {
185
316
  args = ['-o', 'comm'];
186
- stdout = await (0, exec_1.execSecure)('ps', args);
317
+ stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
187
318
  if (stdout) {
188
319
  const lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
189
320
  srvs.forEach((srv) => {
@@ -194,6 +325,7 @@ const services = async (srv) => {
194
325
  name: srv,
195
326
  running: ps.length > 0,
196
327
  startmode: '',
328
+ lastChanged: null,
197
329
  pids: [],
198
330
  cpu: 0,
199
331
  mem: 0
@@ -207,6 +339,7 @@ const services = async (srv) => {
207
339
  name: srv,
208
340
  running: false,
209
341
  startmode: '',
342
+ lastChanged: null,
210
343
  pids: [],
211
344
  cpu: 0,
212
345
  mem: 0
@@ -21,14 +21,8 @@ const system = async () => {
21
21
  result.serial = (0, common_1.getValue)(lines, 'serial number');
22
22
  result.uuid = (0, common_1.getValue)(lines, 'uuid').toLowerCase();
23
23
  result.sku = (0, common_1.getValue)(lines, 'sku number');
24
- const cmd = `echo -n "product_name: "; cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null; echo;
25
- echo -n "product_serial: "; cat /sys/devices/virtual/dmi/id/product_serial 2>/dev/null; echo;
26
- echo -n "product_uuid: "; cat /sys/devices/virtual/dmi/id/product_uuid 2>/dev/null; echo;
27
- echo -n "product_version: "; cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null; echo;
28
- echo -n "sys_vendor: "; cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; echo;`;
29
24
  try {
30
- ({ stdout } = await (0, exec_1.execSave)(cmd));
31
- lines = stdout.split('\n');
25
+ lines = await (0, files_1.readSysfsMany)(files_1.DMI_PATH, ['product_name', 'product_serial', 'product_uuid', 'product_version', 'sys_vendor']);
32
26
  result.manufacturer = result.manufacturer === '' ? (0, common_1.getValue)(lines, 'sys_vendor') : result.manufacturer;
33
27
  result.model = result.model === '' ? (0, common_1.getValue)(lines, 'product_name') : result.model;
34
28
  result.version = result.version === '' ? (0, common_1.getValue)(lines, 'product_version') : result.version;
@@ -89,7 +89,7 @@ const parseUsersLinux = (lines, phase) => {
89
89
  const users = async () => {
90
90
  await (0, common_1.nextTick)();
91
91
  let result = [];
92
- let { stdout } = await (0, exec_1.exec)('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', const_1.execOptsLinux);
92
+ let { stdout } = await (0, exec_1.exec)('export LC_ALL=C.UTF-8; who --ips; echo "---"; w | tail -n +2', const_1.execOptsLinux);
93
93
  let lines = stdout.toString().split('\n');
94
94
  result = parseUsersLinux(lines, 1);
95
95
  if (result.length === 0) {
@@ -4,21 +4,15 @@ exports.uuid = void 0;
4
4
  const promises_1 = require("fs/promises");
5
5
  const common_1 = require("../common");
6
6
  const defaults_1 = require("../common/defaults");
7
- const exec_1 = require("../common/exec");
7
+ const files_1 = require("../common/files");
8
8
  const disk_layout_1 = require("./disk-layout");
9
9
  const uuid = async () => {
10
10
  await (0, common_1.nextTick)();
11
11
  const defaults = defaults_1.initUUID;
12
12
  try {
13
- const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null ||
14
- cat /etc/machine-id 2> /dev/null; echo;
15
- echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;
16
- echo -n "systemuuid: "; cat /sys/devices/virtual/dmi/id/product_uuid 2>/dev/null; echo;`;
17
- const { stdout } = await (0, exec_1.execSave)(cmd);
18
- const lines = stdout.toString().split('\n');
19
- const os = (0, common_1.getValue)(lines, 'os').toLowerCase();
20
- let hardware = (0, common_1.getValue)(lines, 'hardware').toLowerCase();
21
- const systemuuid = (0, common_1.getValue)(lines, 'systemuuid').toLowerCase();
13
+ const os = ((await (0, files_1.readSysfs)('/var/lib/dbus/machine-id')) || (await (0, files_1.readSysfs)('/etc/machine-id'))).toLowerCase();
14
+ let hardware = (await (0, files_1.readSysfs)('/sys/class/dmi/id/product_uuid')).toLowerCase();
15
+ const systemuuid = (await (0, files_1.readSysfs)(`${files_1.DMI_PATH}/product_uuid`)).toLowerCase();
22
16
  if (!hardware) {
23
17
  const lines = (await (0, promises_1.readFile)('/proc/cpuinfo')).toString().split('\n');
24
18
  const serial = (0, common_1.getValue)(lines, 'serial');
@@ -43,7 +43,7 @@ const getWifiNetworkListNmi = async () => {
43
43
  const getWifiNetworkListIw = async (networkInterface) => {
44
44
  const result = [];
45
45
  try {
46
- const { stdout } = await (0, exec_1.exec)(`export LC_ALL=C; iwlist ${networkInterface} scan 2>&1; unset LC_ALL`, const_1.execOptsLinux);
46
+ const { stdout } = await (0, exec_1.exec)(`export LC_ALL=C.UTF-8; iwlist ${networkInterface} scan 2>&1; unset LC_ALL`, const_1.execOptsLinux);
47
47
  let iwlistParts = stdout.split(' Cell ');
48
48
  if (iwlistParts[0].indexOf('resource busy') >= 0) {
49
49
  return -1;
@@ -137,7 +137,7 @@ const wifiNetworks = async () => {
137
137
  let result = await getWifiNetworkListNmi();
138
138
  if (result.length === 0) {
139
139
  try {
140
- const { stdout } = await (0, exec_1.exec)('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', const_1.execOptsLinux);
140
+ const { stdout } = await (0, exec_1.exec)('export LC_ALL=C.UTF-8; iwconfig 2>/dev/null; unset LC_ALL', const_1.execOptsLinux);
141
141
  const iwconfigParts = stdout.split('\n\n');
142
142
  let networkInterface = '';
143
143
  iwconfigParts.forEach((element) => {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.networkInterfaces = void 0;
4
4
  const const_1 = require("./common/const");
5
5
  const networkInterfaces = async (defaultString = '', rescan = true) => {
6
- defaultString = '' + defaultString;
6
+ defaultString = typeof defaultString === 'string' ? defaultString : '';
7
7
  switch (true) {
8
8
  case const_1.LINUX || const_1.ANDROID:
9
9
  return (await import('./linux/network-interfaces.js')).networkInterfaces(defaultString, rescan);
package/dist/observe.d.ts CHANGED
@@ -2,4 +2,4 @@ export declare const observe: (valueObject: {
2
2
  [key: string]: string;
3
3
  }, interval: number, callback: (data: {
4
4
  [key: string]: any;
5
- }) => void) => NodeJS.Timeout;
5
+ }) => void) => NodeJS.Timeout | undefined;
package/dist/observe.js CHANGED
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.observe = void 0;
4
4
  const get_1 = require("./get");
5
5
  const observe = (valueObject, interval, callback) => {
6
+ if (typeof callback !== 'function') {
7
+ return undefined;
8
+ }
9
+ const ms = Math.min(Math.max(Number(interval) || 0, 500), 2147483647);
6
10
  let _data = null;
7
11
  return setInterval(() => {
8
12
  (0, get_1.get)(valueObject).then((data) => {
@@ -11,6 +15,6 @@ const observe = (valueObject, interval, callback) => {
11
15
  callback(data);
12
16
  }
13
17
  });
14
- }, interval);
18
+ }, ms);
15
19
  };
16
20
  exports.observe = observe;
@@ -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;
@@ -0,0 +1 @@
1
+ export declare const serialPorts: () => Promise<import("./common/types").SerialPortData[] | null>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialPorts = void 0;
4
+ const const_1 = require("./common/const");
5
+ const serialPorts = async () => {
6
+ switch (true) {
7
+ case const_1.LINUX || const_1.ANDROID:
8
+ return (await import('./linux/serial-ports.js')).serialPorts();
9
+ case const_1.DARWIN:
10
+ return (await import('./darwin/serial-ports.js')).serialPorts();
11
+ case const_1.WINDOWS:
12
+ return (await import('./windows/serial-ports.js')).serialPorts();
13
+ default:
14
+ return null;
15
+ }
16
+ };
17
+ exports.serialPorts = serialPorts;
package/dist/versions.js CHANGED
@@ -75,15 +75,14 @@ const versions = async (apps) => {
75
75
  };
76
76
  }
77
77
  if (!Array.isArray(apps)) {
78
- apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
79
- apps = apps.split('|');
78
+ apps = typeof apps === 'string' ? apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|').split('|') : [];
80
79
  }
81
80
  const result = {
82
81
  versions: {},
83
82
  counter: 0
84
83
  };
85
84
  apps.forEach((el) => {
86
- if (el) {
85
+ if (el && typeof el === 'string') {
87
86
  for (const key in versionObject) {
88
87
  if (Object.keys(versionObject).includes(key)) {
89
88
  if (key.toLowerCase() === el.toLowerCase() && !Object.keys(result.versions).includes(key)) {
@@ -414,90 +413,45 @@ const versions = async (apps) => {
414
413
  });
415
414
  }
416
415
  if (Object.keys(appsObj.versions).includes('postgresql')) {
417
- if (const_1.LINUX) {
418
- (0, exec_1.exec)('locate bin/postgres')
419
- .then((res) => {
420
- const postgresqlBin = res.stdout.split('\n').sort();
421
- if (postgresqlBin.length) {
422
- (0, exec_1.exec)(postgresqlBin[postgresqlBin.length - 1] + ' -V')
423
- .then((res) => {
424
- if (res.stdout) {
425
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
426
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
416
+ if (const_1.WINDOWS) {
417
+ windows_1.ps.exec('Get-CimInstance Win32_Service | select caption | fl')
418
+ .then((stdout) => {
419
+ const serviceSections = (stdout ? stdout.toString() : '').split(/\n\s*\n/);
420
+ serviceSections.forEach((item) => {
421
+ const lines = item.trim().split('\r\n');
422
+ const srvCaption = (0, common_1.getValue)(lines, 'caption', ':', true).toLowerCase();
423
+ if (srvCaption.indexOf('postgresql') > -1) {
424
+ const parts = srvCaption.split(' server ');
425
+ if (parts.length > 1) {
426
+ appsObj.versions.postgresql = parts[1];
427
427
  }
428
- functionProcessed();
429
- })
430
- .catch(() => {
431
- functionProcessed();
432
- });
433
- }
434
- else {
435
- functionProcessed();
436
- }
428
+ }
429
+ });
430
+ functionProcessed();
437
431
  })
438
432
  .catch(() => {
439
- (0, exec_1.exec)('psql -V')
440
- .then((res) => {
441
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
442
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
443
- appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
444
- functionProcessed();
445
- })
446
- .catch(() => {
447
- functionProcessed();
448
- });
433
+ functionProcessed();
449
434
  });
450
435
  }
451
436
  else {
452
- if (const_1.WINDOWS) {
453
- windows_1.ps.exec('Get-CimInstance Win32_Service | select caption | fl')
454
- .then((stdout) => {
455
- const serviceSections = (stdout ? stdout.toString() : '').split(/\n\s*\n/);
456
- serviceSections.forEach((item) => {
457
- const lines = item.trim().split('\r\n');
458
- const srvCaption = (0, common_1.getValue)(lines, 'caption', ':', true).toLowerCase();
459
- if (srvCaption.indexOf('postgresql') > -1) {
460
- const parts = srvCaption.split(' server ');
461
- if (parts.length > 1) {
462
- appsObj.versions.postgresql = parts[1];
463
- }
464
- }
465
- });
466
- functionProcessed();
467
- })
468
- .catch(() => {
469
- functionProcessed();
470
- });
471
- }
472
- else {
473
- (0, exec_1.exec)('postgres -V')
474
- .then((res) => {
475
- if (res.stdout) {
476
- const postgresql = res.stdout.split('\n')[0].split(' ') || [];
477
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
478
- if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
479
- appsObj.versions.postgresql = postgresql[postgresql.length - 2];
480
- }
437
+ const parsePostgres = (stdout) => {
438
+ const postgresql = stdout.split('\n')[0].split(' ') || [];
439
+ let version = postgresql.length ? postgresql[postgresql.length - 1] : '';
440
+ if (version.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
441
+ version = postgresql[postgresql.length - 2];
442
+ }
443
+ return version.split('-')[0];
444
+ };
445
+ (async () => {
446
+ for (const cmd of ['postgres -V', 'pg_config --version', 'psql -V']) {
447
+ const { stdout } = await (0, exec_1.execSave)(cmd);
448
+ if (stdout) {
449
+ appsObj.versions.postgresql = parsePostgres(stdout);
450
+ break;
481
451
  }
482
- functionProcessed();
483
- })
484
- .catch(() => {
485
- (0, exec_1.exec)('pg_config --version 2> /dev/null')
486
- .then((res) => {
487
- if (res.stdout) {
488
- const postgresql = res.stdout.toString().split('\n')[0].split(' ') || [];
489
- appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
490
- if (appsObj.versions.postgresql.includes('(') && postgresql.length >= 2 && !postgresql[postgresql.length - 2].includes('(')) {
491
- appsObj.versions.postgresql = postgresql[postgresql.length - 2];
492
- }
493
- }
494
- })
495
- .catch(() => { })
496
- .finally(() => {
497
- functionProcessed();
498
- });
499
- });
500
- }
452
+ }
453
+ functionProcessed();
454
+ })();
501
455
  }
502
456
  }
503
457
  if (Object.keys(appsObj.versions).includes('perl')) {
@@ -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 {};