about-system 0.0.18 → 0.0.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.
@@ -1,794 +1,12 @@
1
- import m from "os";
2
- import f from "fs";
3
- import C from "path";
4
- import { execSync as I } from "child_process";
5
- import P from "https";
6
- const M = C.join(m.tmpdir(), "systeminfo-cache.json"), B = {
7
- ip: 300 * 1e3,
8
- cpu: 1440 * 60 * 1e3,
9
- gpu: 1440 * 60 * 1e3,
10
- os: 1440 * 60 * 1e3,
11
- device: 1440 * 60 * 1e3,
12
- kernel: 3600 * 1e3,
13
- pacman: 600 * 1e3,
14
- ports: 300 * 1e3,
15
- containers: 300 * 1e3,
16
- top_process: 5 * 1e3,
17
- disk_used: 60 * 1e3,
18
- ram_used: 10 * 1e3,
19
- services_running: 300 * 1e3,
20
- temperature: 30 * 1e3,
21
- battery: 60 * 1e3,
22
- network_interfaces: 300 * 1e3,
23
- mount_points: 600 * 1e3
24
- }, g = m.platform() === "win32", $ = m.platform() === "darwin", l = m.platform() === "linux", F = "da2d6cc4baa5d1", j = 5e3;
25
- function N() {
26
- try {
27
- if (f.existsSync(M))
28
- return JSON.parse(f.readFileSync(M, "utf8"));
29
- } catch {
30
- }
31
- return {};
32
- }
33
- function O(e) {
34
- try {
35
- f.writeFileSync(M, JSON.stringify(e, null, 2));
36
- } catch {
37
- }
38
- }
39
- function A(e, c) {
40
- if (!e || !e.timestamp) return !1;
41
- const t = Date.now() - e.timestamp, r = B[c] || 6e4;
42
- return t < r;
43
- }
44
- function h(e, c) {
45
- if (!e[c]) return null;
46
- const t = e[c];
47
- return A(t, c) ? t.value : (delete e[c], null);
48
- }
49
- function a(e, c, t) {
50
- e[c] = {
51
- value: t,
52
- timestamp: Date.now()
53
- };
54
- }
55
- function u(e, c = {}) {
56
- try {
57
- const t = g ? `cmd /c ${e}` : e;
58
- return I(t, {
59
- encoding: "utf8",
60
- timeout: 1e4,
61
- stdio: ["pipe", "pipe", "ignore"],
62
- ...c
63
- }).toString().trim();
64
- } catch {
65
- return "";
66
- }
67
- }
68
- function _(e) {
69
- try {
70
- return g ? I(`where ${e}`, { stdio: "ignore" }) : I(`which ${e}`, { stdio: "ignore" }), !0;
71
- } catch {
72
- return !1;
73
- }
74
- }
75
- async function W(e = F, c = j) {
76
- return new Promise((t) => {
77
- const r = `https://ipinfo.io/json${e ? `?token=${e}` : ""}`, n = P.get(r, (s) => {
78
- let o = "";
79
- s.on("data", (i) => o += i), s.on("end", () => {
80
- try {
81
- t(JSON.parse(o));
82
- } catch {
83
- t({});
84
- }
85
- });
86
- });
87
- n.on("error", () => t({})), n.setTimeout(c, () => {
88
- n.destroy(), t({});
89
- });
90
- });
91
- }
92
- const E = {
93
- /**
94
- * Gets the current username
95
- * @returns Current system username
96
- */
97
- user() {
98
- return m.userInfo().username;
99
- },
100
- /**
101
- * Gets the system hostname
102
- * @returns Computer hostname/network name
103
- */
104
- hostname() {
105
- return m.hostname();
106
- },
107
- /**
108
- * Gets public IP address from ipinfo.io
109
- * @param context - Info context with cache and IP info
110
- * @returns Public IPv4 address or empty string
111
- * @example "203.0.113.42"
112
- */
113
- async ip(e) {
114
- const c = h(e.cache, "ip");
115
- if (c) return c;
116
- if (!e.ipInfo)
117
- return a(e.cache, "ip", ""), "";
118
- const t = e.ipInfo.ip || "";
119
- return a(e.cache, "ip", t), t;
120
- },
121
- /**
122
- * Gets local/private IP address(es)
123
- * Tries ifconfig and ip commands on Linux, falls back to Node.js API
124
- * @returns Space-separated local IP addresses (RFC 1918 ranges)
125
- * @example "192.168.1.100" or "10.0.0.50 192.168.1.100"
126
- */
127
- iplocal() {
128
- if (l) {
129
- try {
130
- const r = u("ifconfig 2>/dev/null").match(
131
- /wlan0[\s\S]*?inet (\d+\.\d+\.\d+\.\d+)/
132
- );
133
- if (r)
134
- return r[1];
135
- } catch {
136
- }
137
- try {
138
- const t = u("ip addr show 2>/dev/null"), r = [], n = t.matchAll(/inet (\d+\.\d+\.\d+\.\d+)\/\d+/g);
139
- for (const s of n)
140
- s[1].startsWith("127.") || r.push(s[1]);
141
- if (r.length > 0)
142
- return r.join(" ");
143
- } catch {
144
- }
145
- }
146
- const e = m.networkInterfaces(), c = [];
147
- for (const t of Object.keys(e))
148
- for (const r of e[t] || [])
149
- r.family === "IPv4" && !r.internal && c.push(r.address);
150
- return c.join(" ");
151
- },
152
- /**
153
- * Gets geographic city based on public IP
154
- * @param context - Info context with IP geolocation data
155
- * @returns City name or empty string
156
- * @example "San Francisco", "New York", "London"
157
- */
158
- async city(e) {
159
- const c = h(e.cache, "city");
160
- if (c !== null) return c;
161
- if (!e.ipInfo || !e.ipInfo.city)
162
- return a(e.cache, "city", ""), "";
163
- const t = e.ipInfo.city;
164
- return a(e.cache, "city", t), t;
165
- },
166
- /**
167
- * Gets reverse DNS hostname with HTTP prefix
168
- * @param context - Info context with IP info
169
- * @returns Domain with http:// prefix or empty string
170
- * @example "http://example.com", "http://host-203-0-113-42.example.net"
171
- */
172
- async domain(e) {
173
- const c = h(e.cache, "domain");
174
- if (c !== null) return c;
175
- if (!e.ipInfo || !e.ipInfo.hostname)
176
- return a(e.cache, "domain", ""), "";
177
- const t = `http://${e.ipInfo.hostname}`;
178
- return a(e.cache, "domain", t), t;
179
- },
180
- /**
181
- * Gets Internet Service Provider name
182
- * Strips AS number prefix from organization string
183
- * @param context - Info context with IP info
184
- * @returns ISP name or empty string
185
- * @example "Comcast Cable", "Verizon Business", "Cloudflare Inc"
186
- */
187
- async isp(e) {
188
- const c = h(e.cache, "isp");
189
- if (c !== null) return c;
190
- if (!e.ipInfo || !e.ipInfo.org)
191
- return a(e.cache, "isp", ""), "";
192
- const t = e.ipInfo.org.split(" ").slice(1).join(" ");
193
- return a(e.cache, "isp", t), t;
194
- },
195
- /**
196
- * Gets operating system name and version
197
- * Platform-specific detection for Windows, macOS, and Linux
198
- * @param context - Info context with cache
199
- * @returns OS name and version string
200
- * @example "Windows 11 Pro", "macOS Ventura 13.2.1", "Ubuntu 22.04.3 LTS"
201
- */
202
- os(e) {
203
- const c = h(e.cache, "os");
204
- if (c) return c;
205
- const t = m.platform(), r = m.release();
206
- let n = "";
207
- if (g)
208
- try {
209
- const o = u("ver").match(/Microsoft Windows \[Version ([^\]]+)\]/);
210
- n = o ? `Windows ${o[1]}` : `Windows ${r}`;
211
- } catch {
212
- n = `Windows ${r}`;
213
- }
214
- else if ($)
215
- n = `macOS ${r}`;
216
- else if (l)
217
- try {
218
- const s = f.readFileSync("/etc/os-release", "utf8"), o = s.match(/^NAME="([^"]+)"/m), i = s.match(/^VERSION_ID="([^"]+)"/m);
219
- n = o ? o[1] : "Linux", i && (n += ` ${i[1]}`);
220
- } catch {
221
- n = `Linux ${r}`;
222
- }
223
- else
224
- n = `${t} ${r}`;
225
- return a(e.cache, "os", n), n;
226
- },
227
- /**
228
- * Gets CPU model name and specifications
229
- * Uses platform-specific commands (wmic/lscpu/cpuinfo)
230
- * Automatically strips "with Radeon Graphics" and similar suffixes
231
- * @param context - Info context with cache
232
- * @returns CPU model string or empty string
233
- * @example "Intel Core i7-12700K", "AMD Ryzen 9 5900HX", "Apple M2 Pro"
234
- */
235
- cpu(e) {
236
- const c = h(e.cache, "cpu");
237
- if (c) return c;
238
- let t = "";
239
- if (g) {
240
- try {
241
- const n = u("wmic cpu get name /format:list").match(/Name=(.+)/);
242
- n && (t = n[1].trim());
243
- } catch {
244
- }
245
- if (!t)
246
- try {
247
- const r = u(
248
- 'powershell.exe -Command "Get-WmiObject -Class Win32_Processor | Select-Object -ExpandProperty Name"'
249
- );
250
- r.trim() && (t = r.trim());
251
- } catch {
252
- }
253
- } else if (l) {
254
- try {
255
- const n = u("lscpu").match(/Model name:\s*([^\n,]+)/);
256
- n && (t = n[1].trim());
257
- } catch {
258
- }
259
- if (!t)
260
- try {
261
- const r = f.readFileSync("/proc/cpuinfo", "utf8"), n = r.match(/model name\s*:\s*([^\n]+)/), s = r.match(/Hardware\s*:\s*([^\n]+)/);
262
- n ? t = n[1].trim() : s && (t = s[1].trim());
263
- } catch {
264
- }
265
- } else {
266
- const r = m.cpus();
267
- r.length > 0 && (t = r[0].model.trim().replace(/[\r\n]+/g, " "));
268
- }
269
- return t ? (t = t.trim().replace(/with .*/, ""), a(e.cache, "cpu", t), t) : (a(e.cache, "cpu", ""), "");
270
- },
271
- /**
272
- * Gets graphics card model name
273
- * Extracts GPU info from lspci (Linux) or WMI (Windows)
274
- * Filters out basic/generic display adapters
275
- * @param context - Info context with cache
276
- * @returns GPU model string or empty string
277
- * @example "NVIDIA GeForce RTX 4070", "AMD Radeon RX 6800 XT"
278
- */
279
- gpu(e) {
280
- const c = h(e.cache, "gpu");
281
- if (c !== null) return c;
282
- if (g) {
283
- try {
284
- const r = u(
285
- "wmic path win32_VideoController get name /format:list"
286
- ).match(/Name=(.+)/);
287
- if (r) {
288
- const n = r[1].trim();
289
- if (n && n !== "" && !n.includes("Microsoft Basic"))
290
- return a(e.cache, "gpu", n), n;
291
- }
292
- } catch {
293
- }
294
- try {
295
- const t = u(
296
- `powershell.exe -Command "Get-WmiObject -Class Win32_VideoController | Where-Object {$_.Name -notlike '*Microsoft Basic*'} | Select-Object -First 1 -ExpandProperty Name"`
297
- );
298
- if (t.trim()) {
299
- const r = t.trim();
300
- return a(e.cache, "gpu", r), r;
301
- }
302
- } catch {
303
- }
304
- } else if (l)
305
- try {
306
- const r = u("lspci").match(
307
- /VGA.*?(RTX|GeForce|AMD|Intel|NVIDIA)[^\n]*/i
308
- );
309
- if (r) {
310
- let n = r[0];
311
- const s = n.match(/\[([^\]]+)\]/);
312
- if (s ? n = s[1] : n = n.replace(/^.*VGA[^:]*:\s*/, "").replace(/\s*\(.*\)$/, "").trim(), n)
313
- return a(e.cache, "gpu", n), n;
314
- }
315
- } catch {
316
- }
317
- return a(e.cache, "gpu", ""), "";
318
- },
319
- /**
320
- * Gets root filesystem disk usage percentage
321
- * Uses df command on Linux/Android
322
- * @param context - Info context with cache
323
- * @returns Percentage string or empty string
324
- * @example "45%", "78%"
325
- */
326
- disk_used(e) {
327
- const c = h(e.cache, "disk_used");
328
- if (c !== null) return c;
329
- if (l)
330
- try {
331
- const t = u("df -h");
332
- let r = "";
333
- if (t.includes("/storage/emulated")) {
334
- const n = t.match(/\s+(\d+%)\s+\/storage\/emulated/);
335
- r = n ? n[1] : "";
336
- } else {
337
- const n = t.split(`
338
- `);
339
- for (const s of n)
340
- if (s.trim().endsWith(" /")) {
341
- const o = s.trim().split(/\s+/), i = o.findIndex(
342
- (p) => p.includes("%")
343
- );
344
- if (i !== -1) {
345
- r = o[i];
346
- break;
347
- }
348
- }
349
- if (!r) {
350
- const s = t.match(/(\d+%)\s+\/\s*$/m);
351
- r = s ? s[1] : "";
352
- }
353
- }
354
- return a(e.cache, "disk_used", r), r;
355
- } catch {
356
- }
357
- return a(e.cache, "disk_used", ""), "";
358
- },
359
- /**
360
- * Gets memory usage in gigabytes
361
- * Reads from /proc/meminfo on Linux, falls back to os.totalmem()
362
- * @param context - Info context with cache
363
- * @returns Memory usage as "used/total GB"
364
- * @example "12/32GB", "6/16GB"
365
- */
366
- ram_used(e) {
367
- const c = h(e.cache, "ram_used");
368
- if (c) return c;
369
- if (l)
370
- try {
371
- const p = f.readFileSync("/proc/meminfo", "utf8"), d = p.match(/MemTotal:\s+(\d+) kB/), y = p.match(/MemFree:\s+(\d+) kB/);
372
- if (d && y) {
373
- const w = Math.round(parseInt(d[1]) / 1024), v = Math.round(parseInt(y[1]) / 1024), k = w - v, b = Math.round(w / 1024), S = `${Math.round(k / 1024)}/${b}GB`;
374
- return a(e.cache, "ram_used", S), S;
375
- }
376
- } catch {
377
- }
378
- const t = m.totalmem(), r = m.freemem(), n = t - r, s = Math.round(t / (1024 * 1024 * 1024)), i = `${Math.round(n / (1024 * 1024 * 1024))}/${s}GB`;
379
- return a(e.cache, "ram_used", i), i;
380
- },
381
- /**
382
- * Gets the highest CPU-consuming process
383
- * Uses ps command to find top process by CPU usage (Linux only)
384
- * @param context - Info context with cache
385
- * @returns Process info as "percentage processname" or empty string
386
- * @example "8% firefox", "15% chrome", "3% systemd"
387
- */
388
- top_process(e) {
389
- const c = h(e.cache, "top_process");
390
- if (c !== null) return c;
391
- if (l)
392
- try {
393
- const r = u("ps -eo pcpu,comm --sort=-%cpu --no-headers").split(`
394
- `);
395
- if (r.length > 0) {
396
- const n = r[0].trim().replace(/\s+/, " ").split(" "), s = n[0].replace(/\.\d+/, "%"), o = n[1].split("/").pop(), i = `${s} ${o}`;
397
- return a(e.cache, "top_process", i), i;
398
- }
399
- } catch {
400
- }
401
- return a(e.cache, "top_process", ""), "";
402
- },
403
- /**
404
- * Gets system uptime since last boot
405
- * @returns Uptime formatted as "Xd Yh Zm"
406
- * @example "2d 14h 23m", "0d 3h 45m"
407
- */
408
- uptime() {
409
- const e = m.uptime(), c = Math.floor(e / 86400), t = Math.floor(e % 86400 / 3600), r = Math.floor(e % 3600 / 60);
410
- return `${c}d ${t}h ${r}m`;
411
- },
412
- /**
413
- * Gets device or computer model name
414
- * Uses WMI on Windows, DMI on Linux, getprop on Android
415
- * @param context - Info context with cache
416
- * @returns Device model name or empty string
417
- * @example "Dell OptiPlex 7090", "MacBook Pro 16-inch", "Valve Steam Deck"
418
- */
419
- device(e) {
420
- const c = h(e.cache, "device");
421
- if (c !== null) return c;
422
- if (g) {
423
- try {
424
- const r = u("wmic csproduct get name /format:list").match(/Name=(.+)/);
425
- if (r) {
426
- const n = r[1].trim();
427
- if (n && n !== "")
428
- return a(e.cache, "device", n), n;
429
- }
430
- } catch {
431
- }
432
- try {
433
- const t = u(
434
- 'powershell.exe -Command "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Model"'
435
- );
436
- if (t.trim()) {
437
- const r = t.trim();
438
- return a(e.cache, "device", r), r;
439
- }
440
- } catch {
441
- }
442
- } else if (l)
443
- try {
444
- if (_("getprop")) {
445
- const r = u("getprop ro.product.model");
446
- if (r)
447
- return a(e.cache, "device", r), r;
448
- }
449
- const t = "/sys/devices/virtual/dmi/id/product_name";
450
- if (f.existsSync(t)) {
451
- const r = f.readFileSync(t, "utf8").trim();
452
- if (r)
453
- return a(e.cache, "device", r), r;
454
- }
455
- } catch {
456
- }
457
- return a(e.cache, "device", ""), "";
458
- },
459
- /**
460
- * Gets kernel version string
461
- * Returns the operating system kernel version from os.release()
462
- * @param context - Info context with cache
463
- * @returns Kernel version string
464
- * @example "5.15.0-56-generic", "6.11.11-valve12-1-neptune"
465
- */
466
- kernel(e) {
467
- const c = h(e.cache, "kernel");
468
- if (c) return c;
469
- const t = m.release();
470
- return a(e.cache, "kernel", t), t;
471
- },
472
- /**
473
- * Gets the current shell name
474
- * Uses ps command to find parent process shell (Linux/Unix only)
475
- * @returns Shell name or empty string on Windows
476
- * @example "bash", "zsh", "fish", "nu"
477
- */
478
- shell() {
479
- if (l)
480
- try {
481
- const e = process.ppid;
482
- return u(`ps -p ${e} -o comm=`).split("/").pop() || "";
483
- } catch {
484
- }
485
- return "";
486
- },
487
- /**
488
- * Gets available package managers and development tools
489
- * Checks for package managers (apt, yum, npm, etc.) and editors (nvim, hx)
490
- * @param context - Info context with cache
491
- * @returns Space-separated list of available commands
492
- * @example "apt npm docker nvim", "yay pacman bun hx"
493
- */
494
- pacman(e) {
495
- const c = h(e.cache, "pacman");
496
- if (c !== null) return c;
497
- const n = [
498
- "apt",
499
- "npm",
500
- "uv",
501
- "docker",
502
- "hx",
503
- "nvim",
504
- "bun",
505
- "yay",
506
- "pacman",
507
- "yum",
508
- "dnf",
509
- "zypper",
510
- "emerge",
511
- "apk",
512
- "snap",
513
- "flatpak"
514
- ].filter((s) => _(s)).join(" ");
515
- return a(e.cache, "pacman", n), n;
516
- },
517
- /**
518
- * Gets open TCP ports with service names
519
- * Uses lsof to find listening TCP ports (Linux only)
520
- * @param context - Info context with cache
521
- * @returns Space-separated port+process pairs or empty string
522
- * @example "80http 443http 22ssh", "3000node 5432post"
523
- */
524
- ports(e) {
525
- const c = h(e.cache, "ports");
526
- if (c !== null) return c;
527
- if (l)
528
- try {
529
- const r = u("lsof -nP -iTCP -sTCP:LISTEN").split(`
530
- `).slice(1), n = /* @__PURE__ */ new Set();
531
- r.forEach((o) => {
532
- const i = o.split(/\s+/);
533
- if (i.length >= 9) {
534
- const d = i[8].match(/:(\d+)$/);
535
- if (d) {
536
- const y = d[1], w = i[0].substring(0, 4);
537
- n.add(`${y}${w}`);
538
- }
539
- }
540
- });
541
- const s = Array.from(n).join(" ");
542
- return a(e.cache, "ports", s), s;
543
- } catch {
544
- }
545
- return a(e.cache, "ports", ""), "";
546
- },
547
- /**
548
- * Gets running Docker container names
549
- * Lists active Docker containers with their names
550
- * @param context - Info context with cache
551
- * @returns Space-separated container names or empty string
552
- * @example "nginx redis postgres", "web-app db-server"
553
- */
554
- containers(e) {
555
- const c = h(e.cache, "containers");
556
- if (c !== null) return c;
557
- if (!_("docker"))
558
- return a(e.cache, "containers", ""), "";
559
- try {
560
- if (u("docker ps -q").split(`
561
- `).filter((i) => i.trim()).length === 0)
562
- return a(e.cache, "containers", ""), "";
563
- const n = u(
564
- 'docker ps --format "{{.Names}} {{.Ports}}"'
565
- ).split(`
566
- `).filter((i) => i.trim()), s = [];
567
- n.forEach((i) => {
568
- const [p, d] = i.split(" ");
569
- if (p && (s.push(p), d)) {
570
- const y = d.match(/->(\d+(-\d+)?)\//g);
571
- if (y) {
572
- const w = [
573
- ...new Set(
574
- y.map((v) => v.replace(/->\d+(-\d+)?\//, ""))
575
- )
576
- ];
577
- s.push(...w);
578
- }
579
- }
580
- });
581
- const o = s.join(" ");
582
- return a(e.cache, "containers", o), o;
583
- } catch {
584
- }
585
- return a(e.cache, "containers", ""), "";
586
- },
587
- /**
588
- * Gets available memory in gigabytes
589
- * Reads MemAvailable from /proc/meminfo (Linux only)
590
- * @returns Available memory with "GB available" suffix or empty string
591
- * @example "12GB available", "4GB available"
592
- */
593
- memory_available() {
594
- if (!l) return "";
595
- try {
596
- const c = f.readFileSync("/proc/meminfo", "utf8").match(/MemAvailable:\s+(\d+) kB/);
597
- if (c)
598
- return `${Math.round(
599
- parseInt(c[1]) / 1024 / 1024
600
- )}GB available`;
601
- } catch {
602
- }
603
- return "";
604
- },
605
- /**
606
- * Gets swap memory usage
607
- * Calculates swap usage from /proc/meminfo (Linux only)
608
- * @returns Swap usage as "percentage (size MB) swap" or empty string
609
- * @example "15% (512MB) swap", "0% (0MB) swap"
610
- */
611
- swap_used() {
612
- if (!l) return "";
613
- try {
614
- const e = f.readFileSync("/proc/meminfo", "utf8"), c = e.match(/SwapTotal:\s+(\d+) kB/), t = e.match(/SwapFree:\s+(\d+) kB/);
615
- if (c && t) {
616
- const r = parseInt(c[1]), n = parseInt(t[1]), s = r - n;
617
- if (r > 0) {
618
- const o = Math.round(s / r * 100), i = Math.round(s / 1024);
619
- return `${o}% (${i}MB) swap`;
620
- }
621
- }
622
- } catch {
623
- }
624
- return "";
625
- },
626
- /**
627
- * Gets system load averages
628
- * Reads 1, 5, and 15 minute load averages from /proc/loadavg (Linux only)
629
- * @returns Space-separated load averages (1m 5m 15m) or empty string
630
- * @example "0.52 0.58 0.59", "2.10 1.95 1.88"
631
- */
632
- load_average() {
633
- if (!l) return "";
634
- try {
635
- return f.readFileSync("/proc/loadavg", "utf8").split(" ").slice(0, 3).join(" ");
636
- } catch {
637
- }
638
- return "";
639
- },
640
- /**
641
- * Gets number of logged in users
642
- * Uses who command to count active user sessions (Linux only)
643
- * @returns User count with "users" suffix or empty string
644
- * @example "3 users", "1 users"
645
- */
646
- users_logged_in() {
647
- if (!l) return "";
648
- try {
649
- const c = u("who").split(`
650
- `).filter((t) => t.trim()).length;
651
- if (c > 0)
652
- return `${c} users`;
653
- } catch {
654
- }
655
- return "";
656
- },
657
- /**
658
- * Gets active network interface names
659
- * Lists non-loopback interfaces with IPv4 addresses (Linux only)
660
- * @param context - Info context with cache
661
- * @returns Space-separated interface names or empty string
662
- * @example "eth0 wlan0", "enp0s3"
663
- */
664
- network_interfaces(e) {
665
- const c = h(e.cache, "network_interfaces");
666
- if (c !== null) return c;
667
- if (!l)
668
- return a(e.cache, "network_interfaces", ""), "";
669
- try {
670
- const t = m.networkInterfaces(), r = [];
671
- for (const [s, o] of Object.entries(t))
672
- s !== "lo" && o?.find(
673
- (p) => p.family === "IPv4" && !p.internal
674
- ) && r.push(s);
675
- const n = r.join(" ");
676
- return a(e.cache, "network_interfaces", n), n;
677
- } catch {
678
- }
679
- return a(e.cache, "network_interfaces", ""), "";
680
- },
681
- mount_points(e) {
682
- const c = h(e.cache, "mount_points");
683
- if (c !== null) return c;
684
- if (!l)
685
- return a(e.cache, "mount_points", ""), "";
686
- try {
687
- const r = u("df -h").split(`
688
- `).slice(1), n = [];
689
- r.forEach((o) => {
690
- const i = o.trim().split(/\s+/);
691
- if (i.length >= 6) {
692
- const p = i[5], d = i[4];
693
- !p.startsWith("/dev") && !p.startsWith("/proc") && !p.startsWith("/sys") && p !== "/" && n.push(`${p}(${d})`);
694
- }
695
- });
696
- const s = n.slice(0, 3).join(" ");
697
- return a(e.cache, "mount_points", s), s;
698
- } catch {
699
- }
700
- return a(e.cache, "mount_points", ""), "";
701
- },
702
- services_running(e) {
703
- const c = h(e.cache, "services_running");
704
- if (c !== null) return c;
705
- if (!l)
706
- return a(e.cache, "services_running", ""), "";
707
- try {
708
- let t = 0;
709
- if (_("systemctl") ? t = u(
710
- "systemctl list-units --type=service --state=running --no-pager"
711
- ).split(`
712
- `).filter((n) => n.includes(".service")).length : _("service") && (t = u("service --status-all").split(`
713
- `).filter((n) => n.includes("+")).length), t > 0) {
714
- const r = `${t} services`;
715
- return a(e.cache, "services_running", r), r;
716
- }
717
- } catch {
718
- }
719
- return a(e.cache, "services_running", ""), "";
720
- },
721
- temperature(e) {
722
- const c = h(e.cache, "temperature");
723
- if (c !== null) return c;
724
- if (!l)
725
- return a(e.cache, "temperature", ""), "";
726
- try {
727
- const t = [
728
- "/sys/class/thermal/thermal_zone0/temp",
729
- "/sys/class/hwmon/hwmon0/temp1_input",
730
- "/sys/class/hwmon/hwmon1/temp1_input"
731
- ];
732
- for (const r of t)
733
- if (f.existsSync(r)) {
734
- const n = f.readFileSync(r, "utf8").trim(), s = Math.round(parseInt(n) / 1e3);
735
- if (s > 0 && s < 150) {
736
- const o = `${s}°C`;
737
- return a(e.cache, "temperature", o), o;
738
- }
739
- }
740
- } catch {
741
- }
742
- return a(e.cache, "temperature", ""), "";
743
- },
744
- battery(e) {
745
- const c = h(e.cache, "battery");
746
- if (c !== null) return c;
747
- if (!l)
748
- return a(e.cache, "battery", ""), "";
749
- try {
750
- const t = "/sys/class/power_supply/BAT0", r = `${t}/capacity`, n = `${t}/status`;
751
- if (f.existsSync(r)) {
752
- const s = f.readFileSync(r, "utf8").trim(), o = f.existsSync(n) ? f.readFileSync(n, "utf8").trim() : "Unknown", d = `${parseInt(s)}%${o === "Charging" ? "+" : ""}`;
753
- return a(e.cache, "battery", d), d;
754
- }
755
- } catch {
756
- }
757
- return a(e.cache, "battery", ""), "";
758
- },
759
- screen_resolution() {
760
- if (!l) return "";
761
- try {
762
- if (process.env.DISPLAY) {
763
- const c = u("xrandr").match(/(\d+x\d+)\+\d+\+\d+/);
764
- if (c)
765
- return c[1];
766
- }
767
- } catch {
768
- }
769
- return "";
770
- }
771
- };
772
- async function R(e = {}) {
773
- const c = N(), t = { cache: c }, r = h(c, "ipInfo");
774
- r ? t.ipInfo = r : (t.ipInfo = await W(), a(c, "ipInfo", t.ipInfo));
775
- const n = {
776
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
777
- platform: g ? "windows" : $ ? "macos" : l ? "linux" : "unknown"
778
- };
779
- for (const [s, o] of Object.entries(E))
780
- try {
781
- const i = await o(t);
782
- n[s] = i;
783
- } catch {
784
- n[s] = "";
785
- }
786
- return O(c), n;
787
- }
1
+ import "os";
2
+ import "fs";
3
+ import "https";
4
+ import "path";
5
+ import { g as m, i as r, l as p, s as n } from "./system-info-api-DAF2cjeE.js";
788
6
  export {
789
- R as getSystemInfo,
790
- E as infoFunctions,
791
- N as loadCache,
792
- O as saveCache
7
+ m as getSystemInfo,
8
+ r as infoFunctions,
9
+ p as loadCache,
10
+ n as saveCache
793
11
  };
794
12
  //# sourceMappingURL=system-info-api.js.map