Merge branch 'main' of github.com:hydralauncher/hydra

This commit is contained in:
Chubby Granny Chaser 2024-12-16 16:21:43 +00:00
commit 1e99dae9de
No known key found for this signature in database
6 changed files with 31 additions and 7 deletions

1
.python-version Normal file
View File

@ -0,0 +1 @@
3.9.20

View File

@ -24,7 +24,11 @@ const closeGame = async (
if (!game) return; if (!game) return;
const gameProcess = processes.find((runningProcess) => { const gameProcess = processes.find((runningProcess) => {
return runningProcess.exe === game.executablePath; if (process.platform === "linux") {
return runningProcess.name === game.executablePath?.split("/").at(-1);
} else {
return runningProcess.exe === game.executablePath;
}
}); });
if (gameProcess) { if (gameProcess) {

View File

@ -35,4 +35,5 @@ export interface LibtorrentPayload {
export interface ProcessPayload { export interface ProcessPayload {
exe: string; exe: string;
pid: number; pid: number;
name: string;
} }

View File

@ -14,6 +14,20 @@ export const gamesPlaytime = new Map<
const TICKS_TO_UPDATE_API = 120; const TICKS_TO_UPDATE_API = 120;
let currentTick = 1; let currentTick = 1;
const getSystemProcessSet = async () => {
const processes = await PythonInstance.getProcessList();
if (process.platform === "linux")
return new Set(processes.map((process) => process.name));
return new Set(processes.map((process) => process.exe));
};
const getExecutable = (game: Game) => {
if (process.platform === "linux")
return game.executablePath?.split("/").at(-1);
return game.executablePath;
};
export const watchProcesses = async () => { export const watchProcesses = async () => {
const games = await gameRepository.find({ const games = await gameRepository.find({
where: { where: {
@ -23,14 +37,15 @@ export const watchProcesses = async () => {
}); });
if (games.length === 0) return; if (games.length === 0) return;
const processes = await PythonInstance.getProcessList();
const processSet = new Set(processes.map((process) => process.exe)); const processSet = await getSystemProcessSet();
for (const game of games) { for (const game of games) {
const executablePath = game.executablePath!; const executable = getExecutable(game);
const gameProcess = processSet.has(executablePath); if (!executable) continue;
const gameProcess = processSet.has(executable);
if (gameProcess) { if (gameProcess) {
if (gamesPlaytime.has(game.id)) { if (gamesPlaytime.has(game.id)) {

View File

@ -195,7 +195,7 @@ export class WindowManager {
this.mainWindow?.focus(); this.mainWindow?.focus();
} }
public static createSystemTray(language: string) { public static async createSystemTray(language: string) {
let tray: Tray; let tray: Tray;
if (process.platform === "darwin") { if (process.platform === "darwin") {
@ -263,6 +263,7 @@ export class WindowManager {
}, },
]); ]);
tray.setContextMenu(contextMenu);
return contextMenu; return contextMenu;
}; };
@ -274,6 +275,8 @@ export class WindowManager {
tray.setToolTip("Hydra"); tray.setToolTip("Hydra");
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
await updateSystemTray();
tray.addListener("click", () => { tray.addListener("click", () => {
if (this.mainWindow) { if (this.mainWindow) {
if ( if (

View File

@ -60,7 +60,7 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers() self.end_headers()
return return
process_list = [proc.info for proc in psutil.process_iter(['exe', 'pid', 'username'])] process_list = [proc.info for proc in psutil.process_iter(['exe', 'pid', 'name'])]
self.send_response(200) self.send_response(200)
self.send_header("Content-type", "application/json") self.send_header("Content-type", "application/json")