Skip to content

Commit

Permalink
Merge pull request #1230 from hydralauncher/fix/linux-game-tracking
Browse files Browse the repository at this point in the history
fix: linux game tracking and closed button
  • Loading branch information
JackEnx authored Dec 13, 2024
2 parents 95d320a + b2d6d7e commit ff917b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.20
6 changes: 5 additions & 1 deletion src/main/events/library/close-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const closeGame = async (
if (!game) return;

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) {
Expand Down
1 change: 1 addition & 0 deletions src/main/services/download/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export interface LibtorrentPayload {
export interface ProcessPayload {
exe: string;
pid: number;
name: string;
}
23 changes: 19 additions & 4 deletions src/main/services/process-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export const gamesPlaytime = new Map<
const TICKS_TO_UPDATE_API = 120;
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 () => {
const games = await gameRepository.find({
where: {
Expand All @@ -23,14 +37,15 @@ export const watchProcesses = async () => {
});

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) {
const executablePath = game.executablePath!;
const executable = getExecutable(game);

if (!executable) continue;

const gameProcess = processSet.has(executablePath);
const gameProcess = processSet.has(executable);

if (gameProcess) {
if (gamesPlaytime.has(game.id)) {
Expand Down
2 changes: 1 addition & 1 deletion torrent-client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def do_GET(self):
self.end_headers()
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_header("Content-type", "application/json")
Expand Down

0 comments on commit ff917b7

Please sign in to comment.