mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: use psList on windows (~25ms vs ~320ms)
This commit is contained in:
parent
46a099118e
commit
1822724df2
@ -1,12 +1,5 @@
|
||||
import psList from "ps-list";
|
||||
import { tasklist } from "tasklist";
|
||||
|
||||
export const getProcesses = async () => {
|
||||
if (process.platform === "win32") {
|
||||
return tasklist().then((tasks) =>
|
||||
tasks.map((task) => ({ ...task, name: task.imageName }))
|
||||
);
|
||||
}
|
||||
|
||||
return psList();
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import path from "node:path";
|
||||
|
||||
import { IsNull, Not } from "typeorm";
|
||||
|
||||
import { exec } from "child_process"
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { getProcesses } from "@main/helpers";
|
||||
import { WindowManager } from "./window-manager";
|
||||
@ -14,13 +14,21 @@ export const startProcessWatcher = async () => {
|
||||
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
await sleep(sleepTime);
|
||||
|
||||
const games = await gameRepository.find({
|
||||
where: {
|
||||
executablePath: Not(IsNull()),
|
||||
},
|
||||
});
|
||||
|
||||
if (games.length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.time("getProcesses")
|
||||
const processes = await getProcesses();
|
||||
console.timeEnd("getProcesses")
|
||||
|
||||
for (const game of games) {
|
||||
const gameProcess = processes.find((runningProcess) => {
|
||||
@ -55,15 +63,10 @@ export const startProcessWatcher = async () => {
|
||||
gameRepository.update(game.id, {
|
||||
lastTimePlayed: new Date().toUTCString(),
|
||||
});
|
||||
|
||||
gamesPlaytime.set(game.id, performance.now());
|
||||
await sleep(sleepTime);
|
||||
continue;
|
||||
}
|
||||
|
||||
gamesPlaytime.set(game.id, performance.now());
|
||||
|
||||
await sleep(sleepTime);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -73,8 +76,6 @@ export const startProcessWatcher = async () => {
|
||||
WindowManager.mainWindow.webContents.send("on-game-close", game.id);
|
||||
}
|
||||
}
|
||||
|
||||
await sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -8866,7 +8866,7 @@ proxy-from-env@^1.1.0:
|
||||
|
||||
ps-list@^8.1.1:
|
||||
version "8.1.1"
|
||||
resolved "https://registry.npmjs.org/ps-list/-/ps-list-8.1.1.tgz"
|
||||
resolved "https://registry.yarnpkg.com/ps-list/-/ps-list-8.1.1.tgz#9ff1952b26a9a07fcc05270407e60544237ae581"
|
||||
integrity sha512-OPS9kEJYVmiO48u/B9qneqhkMvgCxT+Tm28VCEJpheTpl8cJ0ffZRRNgS5mrQRTrX5yRTpaJ+hRDeefXYmmorQ==
|
||||
|
||||
psl@^1.1.33:
|
||||
|
Loading…
Reference in New Issue
Block a user