mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: run fastfile binary from resources folder
feat: run process watcher each 300ms feat: add build step to copy fastlist from node_modules feat: create postinstall script to copy fastlist binary remove debug logs
This commit is contained in:
parent
b5d1c1a0b0
commit
2194a5ac21
6 changed files with 44 additions and 10 deletions
|
@ -4,12 +4,13 @@ import { gameRepository } from "@main/repository";
|
|||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { getProcesses } from "@main/helpers";
|
||||
import { app } from "electron";
|
||||
|
||||
const closeGame = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
const processes = await getProcesses();
|
||||
const processes = await getProcesses(app.isPackaged);
|
||||
const game = await gameRepository.findOne({ where: { id: gameId } });
|
||||
|
||||
const gameProcess = processes.find((runningProcess) => {
|
||||
|
|
|
@ -1,5 +1,32 @@
|
|||
import psList from "ps-list";
|
||||
import path from "node:path";
|
||||
import childProcess from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
export const getProcesses = async () => {
|
||||
return psList();
|
||||
const TEN_MEGABYTES = 1000 * 1000 * 10;
|
||||
const execFile = promisify(childProcess.execFile);
|
||||
|
||||
export const getProcesses = async (isPackaged: boolean) => {
|
||||
if (process.platform == "win32") {
|
||||
const binaryPath = isPackaged
|
||||
? path.join(process.resourcesPath, "fastlist.exe")
|
||||
: path.join(__dirname, "..", "..", "resources", "fastlist.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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,18 +4,18 @@ import { IsNull, Not } from "typeorm";
|
|||
import { gameRepository } from "@main/repository";
|
||||
import { getProcesses } from "@main/helpers";
|
||||
import { WindowManager } from "./window-manager";
|
||||
import { app } from "electron";
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
export const startProcessWatcher = async () => {
|
||||
const sleepTime = 100;
|
||||
const sleepTime = 300;
|
||||
const gamesPlaytime = new Map<number, number>();
|
||||
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
await sleep(sleepTime);
|
||||
|
||||
console.time("loopTotalTime");
|
||||
const games = await gameRepository.find({
|
||||
where: {
|
||||
executablePath: Not(IsNull()),
|
||||
|
@ -26,9 +26,7 @@ export const startProcessWatcher = async () => {
|
|||
continue;
|
||||
}
|
||||
|
||||
console.time("getProcesses");
|
||||
const processes = await getProcesses();
|
||||
console.timeEnd("getProcesses");
|
||||
const processes = await getProcesses(app.isPackaged);
|
||||
|
||||
for (const game of games) {
|
||||
const basename = path.win32.basename(game.executablePath);
|
||||
|
@ -73,6 +71,5 @@ export const startProcessWatcher = async () => {
|
|||
}
|
||||
}
|
||||
}
|
||||
console.timeEnd("loopTotalTime");
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue