mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +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
854b23e4ef
commit
0bbd7d013f
3
.gitignore
vendored
3
.gitignore
vendored
@ -106,3 +106,6 @@ resources/dist/
|
|||||||
|
|
||||||
# Sentry Config File
|
# Sentry Config File
|
||||||
.env.sentry-build-plugin
|
.env.sentry-build-plugin
|
||||||
|
|
||||||
|
# Fastlist binary
|
||||||
|
resources/fastlist.exe
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
"make": "electron-forge make",
|
"make": "electron-forge make",
|
||||||
"publish": "electron-forge publish",
|
"publish": "electron-forge publish",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"format": "prettier . --write"
|
"format": "prettier . --write",
|
||||||
|
"postinstall": "python3 ./postinstall.py"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-forge/cli": "^7.3.0",
|
"@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 { registerEvent } from "../register-event";
|
||||||
import { getProcesses } from "@main/helpers";
|
import { getProcesses } from "@main/helpers";
|
||||||
|
import { app } from "electron";
|
||||||
|
|
||||||
const closeGame = async (
|
const closeGame = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
gameId: number
|
gameId: number
|
||||||
) => {
|
) => {
|
||||||
const processes = await getProcesses();
|
const processes = await getProcesses(app.isPackaged);
|
||||||
const game = await gameRepository.findOne({ where: { id: gameId } });
|
const game = await gameRepository.findOne({ where: { id: gameId } });
|
||||||
|
|
||||||
const gameProcess = processes.find((runningProcess) => {
|
const gameProcess = processes.find((runningProcess) => {
|
||||||
|
@ -1,5 +1,32 @@
|
|||||||
import psList from "ps-list";
|
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 () => {
|
const TEN_MEGABYTES = 1000 * 1000 * 10;
|
||||||
return psList();
|
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 { gameRepository } from "@main/repository";
|
||||||
import { getProcesses } from "@main/helpers";
|
import { getProcesses } from "@main/helpers";
|
||||||
import { WindowManager } from "./window-manager";
|
import { WindowManager } from "./window-manager";
|
||||||
|
import { app } from "electron";
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
export const startProcessWatcher = async () => {
|
export const startProcessWatcher = async () => {
|
||||||
const sleepTime = 100;
|
const sleepTime = 300;
|
||||||
const gamesPlaytime = new Map<number, number>();
|
const gamesPlaytime = new Map<number, number>();
|
||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
await sleep(sleepTime);
|
await sleep(sleepTime);
|
||||||
|
|
||||||
console.time("loopTotalTime");
|
|
||||||
const games = await gameRepository.find({
|
const games = await gameRepository.find({
|
||||||
where: {
|
where: {
|
||||||
executablePath: Not(IsNull()),
|
executablePath: Not(IsNull()),
|
||||||
@ -26,9 +26,7 @@ export const startProcessWatcher = async () => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.time("getProcesses");
|
const processes = await getProcesses(app.isPackaged);
|
||||||
const processes = await getProcesses();
|
|
||||||
console.timeEnd("getProcesses");
|
|
||||||
|
|
||||||
for (const game of games) {
|
for (const game of games) {
|
||||||
const basename = path.win32.basename(game.executablePath);
|
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