-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathgetAvailablePipes.native.ts
More file actions
29 lines (28 loc) · 849 Bytes
/
Copy pathgetAvailablePipes.native.ts
File metadata and controls
29 lines (28 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { readdir } from "node:fs/promises";
import { tmpdir } from "node:os";
export const getAvailablePipes = async (): Promise<number[]> => {
const pipes = new Set<number>();
try {
if (process.platform === "win32") {
const files = await readdir("\\\\.\\pipe\\");
for (const file of files) {
if (file.startsWith("discord-ipc-")) {
const id = parseInt(file.replace("discord-ipc-", ""), 10);
if (!isNaN(id)) pipes.add(id);
}
}
} else {
const tempDir = process.env.XDG_RUNTIME_DIR ?? tmpdir();
const files = await readdir(tempDir);
for (const file of files) {
if (file.startsWith("discord-ipc-")) {
const id = parseInt(file.replace("discord-ipc-", ""), 10);
if (!isNaN(id)) pipes.add(id);
}
}
}
} catch {
// Ignore read errors
}
return Array.from(pipes).sort((a, b) => a - b);
};