From fcfaae7b582c1b98f49fa14be6d2b2eba3b68e0d Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:51:15 -0300 Subject: [PATCH] refactor: move exec command to a function --- src/main/services/process-watcher.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 2922fcfb..3fcc5269 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -7,6 +7,11 @@ import { Game } from "@main/entity"; import axios from "axios"; import { exec } from "child_process"; +const commands = { + findGameExecutableWithWineProcess: (executable: string) => + `lsof -c wine 2>/dev/null | grep -i ${executable} | awk \'{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}\'`, +}; + export const gamesPlaytime = new Map< number, { lastTick: number; firstTick: number; lastSyncTick: number } @@ -135,7 +140,7 @@ export const watchProcesses = async () => { if (process.platform === "linux") { if (executable.endsWith(".exe")) { exec( - `lsof -c wine 2>/dev/null | grep -i ${executable} | awk \'{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}\'`, + commands.findGameExecutableWithWineProcess(executable), (err, out) => { if (err) return;