mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
41 lines
1,022 B
TypeScript
41 lines
1,022 B
TypeScript
import psList from "ps-list";
|
|
import path from "node:path";
|
|
import childProcess from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import { app } from "electron";
|
|
|
|
const TEN_MEGABYTES = 1000 * 1000 * 10;
|
|
const execFile = promisify(childProcess.execFile);
|
|
|
|
export const getProcesses = async () => {
|
|
if (process.platform == "win32") {
|
|
const binaryPath = app.isPackaged
|
|
? path.join(process.resourcesPath, "fastlist.exe")
|
|
: path.join(
|
|
__dirname,
|
|
"..",
|
|
"..",
|
|
"node_modules",
|
|
"ps-list",
|
|
"vendor",
|
|
"fastlist-0.3.0-x64.exe"
|
|
);
|
|
|
|
const { stdout } = await execFile(binaryPath, {
|
|
maxBuffer: TEN_MEGABYTES,
|
|
windowsHide: true,
|
|
});
|
|
|
|
return stdout
|
|
.trim()
|
|
.split("\r\n")
|
|
.map((line) => line.split("\t"))
|
|
.map(([pid, ppid, name]) => ({
|
|
pid: Number.parseInt(pid, 10),
|
|
ppid: Number.parseInt(ppid, 10),
|
|
name,
|
|
}));
|
|
} else {
|
|
return psList();
|
|
}
|
|
};
|