mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54:55 +03: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
cb82424eb2
commit
e4133e9a90
3
.gitignore
vendored
3
.gitignore
vendored
@ -106,3 +106,6 @@ resources/dist/
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
|
||||
# Fastlist binary
|
||||
resources/fastlist.exe
|
||||
|
@ -17,7 +17,8 @@
|
||||
"make": "electron-forge make",
|
||||
"publish": "electron-forge publish",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier . --write"
|
||||
"format": "prettier . --write",
|
||||
"postinstall": "python3 ./postinstall.py"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^7.3.0",
|
||||
|
5
postinstall.py
Normal file
5
postinstall.py
Normal file
@ -0,0 +1,5 @@
|
||||
import shutil
|
||||
import platform
|
||||
|
||||
if platform.system() == "Windows":
|
||||
shutil.copy("node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe", "resources/fastlist.exe")
|
@ -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…
Reference in New Issue
Block a user