From 55646443780ca2da7d8fabd0a26c81c6f46e58fc Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:48:50 -0300 Subject: [PATCH 1/2] refactor: rpc executable objects --- .gitignore | 1 + .python-version | 1 - src/main/services/process-watcher.ts | 79 +++++++++++++++++----------- 3 files changed, 48 insertions(+), 33 deletions(-) delete mode 100644 .python-version diff --git a/.gitignore b/.gitignore index 84771ebb4..134ba8d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ out ludusavi/ hydra-python-rpc/ aria2/ +./python-version diff --git a/.python-version b/.python-version deleted file mode 100644 index 943290866..000000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.9.20 diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 6d8525bf7..c6cb7e102 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -21,6 +21,7 @@ export const gamesPlaytime = new Map< interface ExecutableInfo { name: string; os: string; + exe: string; } interface GameExecutables { @@ -30,47 +31,65 @@ interface GameExecutables { const TICKS_TO_UPDATE_API = 120; let currentTick = 1; -const gameExecutables = ( - await axios - .get( - import.meta.env.MAIN_VITE_EXTERNAL_RESOURCES_URL + - "/game-executables.json" - ) - .catch(() => { - return { data: {} }; - }) -).data as GameExecutables; +const isWindowsPlatform = process.platform === "win32"; +const isLinuxPlatform = process.platform === "linux"; + +const getGameExecutables = async () => { + const gameExecutables = ( + await axios + .get( + import.meta.env.MAIN_VITE_EXTERNAL_RESOURCES_URL + + "/game-executables.json" + ) + .catch(() => { + return { data: {} }; + }) + ).data as GameExecutables; + + Object.keys(gameExecutables).forEach((key) => { + gameExecutables[key] = gameExecutables[key] + .filter((executable) => { + if (isWindowsPlatform) { + return executable.os === "win32"; + } else if (isLinuxPlatform) { + return executable.os === "linux" || executable.os === "win32"; + } + return false; + }) + .map((executable) => { + return { + name: isWindowsPlatform + ? executable.name.replace(/\//g, "\\") + : executable.name, + os: executable.os, + exe: executable.name.slice(executable.name.lastIndexOf("/") + 1), + }; + }); + }); + + return gameExecutables; +}; + +const gameExecutables = await getGameExecutables(); const findGamePathByProcess = ( processMap: Map>, gameId: string ) => { - const executables = gameExecutables[gameId].filter((info) => { - if (process.platform === "linux" && info.os === "linux") return true; - return info.os === "win32"; - }); + const executables = gameExecutables[gameId]; for (const executable of executables) { - const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); - - if (!exe) continue; - - const pathSet = processMap.get(exe); + const pathSet = processMap.get(executable.exe); if (pathSet) { - const executableName = - process.platform === "win32" - ? executable.name.replace(/\//g, "\\") - : executable.name; - pathSet.forEach((path) => { - if (path.toLowerCase().endsWith(executableName)) { + if (path.toLowerCase().endsWith(executable.name)) { gameRepository.update( { objectID: gameId, shop: "steam" }, { executablePath: path } ); - if (process.platform === "linux") { + if (isLinuxPlatform) { exec(commands.findWineDir, (err, out) => { if (err) return; @@ -105,7 +124,7 @@ const getSystemProcessMap = async () => { map.set(key, currentSet.add(value)); }); - if (process.platform === "linux") { + if (isLinuxPlatform) { await new Promise((res) => { exec(commands.findWineExecutables, (err, out) => { if (err) { @@ -152,7 +171,6 @@ export const watchProcesses = async () => { for (const game of games) { const executablePath = game.executablePath; - if (!executablePath) { if (gameExecutables[game.objectID]) { findGamePathByProcess(processMap, game.objectID); @@ -161,10 +179,7 @@ export const watchProcesses = async () => { } const executable = executablePath - .slice( - executablePath.lastIndexOf(process.platform === "win32" ? "\\" : "/") + - 1 - ) + .slice(executablePath.lastIndexOf(isWindowsPlatform ? "\\" : "/") + 1) .toLowerCase(); const hasProcess = processMap.get(executable)?.has(executablePath); From 90841bf5e4300f61e1e3e8cf5dd79b6ff5fcf845 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:50:40 -0300 Subject: [PATCH 2/2] fix: gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 134ba8d5d..68b8342c5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ out ludusavi/ hydra-python-rpc/ aria2/ -./python-version +.python-version