From b8b000d88ca5a7990bfdeda05492891a59ca2760 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:36:16 -0300 Subject: [PATCH 01/25] refactor: change game process set to map --- src/main/services/process-watcher.ts | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index fd9bb148..ce9d060b 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -14,18 +14,24 @@ export const gamesPlaytime = new Map< const TICKS_TO_UPDATE_API = 120; let currentTick = 1; -const getSystemProcessSet = async () => { +const getSystemProcessMap = 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 map = new Map>(); + + processes.forEach((process) => { + const [key, value] = [process.name?.toLowerCase(), process.exe]; + + if (!key || !value) return; + + map.set(key, (map.get(key) ?? new Set()).add(value)); + }); + + return map; }; -const getExecutable = (game: Game) => { - if (process.platform === "linux") - return game.executablePath?.split("/").at(-1); - return game.executablePath; +const getExecutable = (path: string) => { + return path.slice(path.lastIndexOf("/") + 1); }; export const watchProcesses = async () => { @@ -38,14 +44,14 @@ export const watchProcesses = async () => { if (games.length === 0) return; - const processSet = await getSystemProcessSet(); + const processMap = await getSystemProcessMap(); for (const game of games) { - const executable = getExecutable(game); + if (!game.executablePath) continue; - if (!executable) continue; + const executable = getExecutable(game.executablePath); - const gameProcess = processSet.has(executable); + const gameProcess = processMap.get(executable)?.has(game.executablePath); if (gameProcess) { if (gamesPlaytime.has(game.id)) { From 19485b5ba1522133181a27220ed98c57f41f5d99 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:57:49 -0300 Subject: [PATCH 02/25] feature: find game in execution executable path --- src/main/services/process-watcher.ts | 79 +++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index ce9d060b..311400b7 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -5,15 +5,86 @@ import { createGame, updateGamePlaytime } from "./library-sync"; import type { GameRunning } from "@types"; import { PythonInstance } from "./download"; import { Game } from "@main/entity"; +import axios from "axios"; export const gamesPlaytime = new Map< number, { lastTick: number; firstTick: number; lastSyncTick: number } >(); +interface ExecutableInfo { + name: string; + os: string; +} + +interface GameExecutables { + [key: string]: ExecutableInfo[]; +} + const TICKS_TO_UPDATE_API = 120; let currentTick = 1; +const gameExecutables = ( + await axios + .get("https://assets.hydralauncher.gg/game-executables.json") + .catch(() => { + return { data: {} }; + }) +).data as GameExecutables; + +const gamesIdWithoutPath = async () => { + const games = await gameRepository.find({ + where: { + executablePath: IsNull(), + isDeleted: false, + }, + }); + + const gameExecutableIds: string[] = []; + + for (const game of games) { + const has = gameExecutables[game.objectID]; + + if (has) { + gameExecutableIds.push(game.objectID); + } + } + + return gameExecutableIds; +}; + +const findGamePathByProcess = ( + processMap: Map>, + gameIds: string[] +) => { + for (const id of gameIds) { + if (process.platform === "win32") { + const executables = gameExecutables[id].filter( + (info) => info.os === "win32" + ); + + for (const executable of executables) { + const exe = getExecutable(executable.name); + + if (!exe) continue; + + const hasProcess = processMap.get(exe); + + if (hasProcess) { + for (const path of [...hasProcess]) { + if (path.toLowerCase().endsWith(executable.name)) { + gameRepository.update( + { objectID: id, shop: "steam" }, + { executablePath: path } + ); + } + } + } + } + } + } +}; + const getSystemProcessMap = async () => { const processes = await PythonInstance.getProcessList(); @@ -35,6 +106,8 @@ const getExecutable = (path: string) => { }; export const watchProcesses = async () => { + const gameIds = await gamesIdWithoutPath(); + const games = await gameRepository.find({ where: { executablePath: Not(IsNull()), @@ -42,10 +115,14 @@ export const watchProcesses = async () => { }, }); - if (games.length === 0) return; + if (!games.length && !gameIds.length) return; const processMap = await getSystemProcessMap(); + findGamePathByProcess(processMap, gameIds); + + if (!games.length) return; + for (const game of games) { if (!game.executablePath) continue; From d17abdcd1152b2a04e97cd9e9d7b4d009bd5e3a3 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:17:46 -0300 Subject: [PATCH 03/25] refactor: games id without path get only games objectID --- src/main/services/process-watcher.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 311400b7..08d513da 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -38,6 +38,9 @@ const gamesIdWithoutPath = async () => { executablePath: IsNull(), isDeleted: false, }, + select: { + objectID: true, + }, }); const gameExecutableIds: string[] = []; From 08d320ad1c4794e9d93152e66393f3e7bc0b3509 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:34:00 -0300 Subject: [PATCH 04/25] fix: win32 path --- src/main/services/process-watcher.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 08d513da..9a99cbe2 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -75,7 +75,12 @@ const findGamePathByProcess = ( if (hasProcess) { for (const path of [...hasProcess]) { - if (path.toLowerCase().endsWith(executable.name)) { + const executableName = + process.platform === "win32" + ? executable.name.replace("/", "\\") + : executable.name; + + if (path.toLowerCase().endsWith(executableName)) { gameRepository.update( { objectID: id, shop: "steam" }, { executablePath: path } @@ -105,7 +110,9 @@ const getSystemProcessMap = async () => { }; const getExecutable = (path: string) => { - return path.slice(path.lastIndexOf("/") + 1); + return path.slice( + path.lastIndexOf(process.platform === "win32" ? "\\" : "/") + 1 + ); }; export const watchProcesses = async () => { From c2a52d3c180c9ade28fbf1f63ab27773295e32ac Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:35:12 -0300 Subject: [PATCH 05/25] refactor: reduce code redundance --- src/main/services/process-watcher.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 9a99cbe2..573b4feb 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -43,17 +43,9 @@ const gamesIdWithoutPath = async () => { }, }); - const gameExecutableIds: string[] = []; - - for (const game of games) { - const has = gameExecutables[game.objectID]; - - if (has) { - gameExecutableIds.push(game.objectID); - } - } - - return gameExecutableIds; + return games + .filter((game) => gameExecutables[game.objectID]) + .map((game) => game.objectID); }; const findGamePathByProcess = ( From e87f28747669a228b4c4f40b06391cc33d782208 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:37:50 -0300 Subject: [PATCH 06/25] refactor: remove redundant plataform validation --- src/main/services/process-watcher.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 573b4feb..f3f06109 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -67,12 +67,9 @@ const findGamePathByProcess = ( if (hasProcess) { for (const path of [...hasProcess]) { - const executableName = - process.platform === "win32" - ? executable.name.replace("/", "\\") - : executable.name; - - if (path.toLowerCase().endsWith(executableName)) { + if ( + path.toLowerCase().endsWith(executable.name.replace(/\//g, "\\")) + ) { gameRepository.update( { objectID: id, shop: "steam" }, { executablePath: path } From 5607f6d524e654717bb4f85beb3d6590a854e6a8 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:42:07 -0300 Subject: [PATCH 07/25] refactor: move executable name replate outside the forof --- src/main/services/process-watcher.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index f3f06109..fda22a56 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -66,10 +66,10 @@ const findGamePathByProcess = ( const hasProcess = processMap.get(exe); if (hasProcess) { + const executableName = executable.name.replace(/\//g, "\\"); + for (const path of [...hasProcess]) { - if ( - path.toLowerCase().endsWith(executable.name.replace(/\//g, "\\")) - ) { + if (path.toLowerCase().endsWith(executableName)) { gameRepository.update( { objectID: id, shop: "steam" }, { executablePath: path } From d9adc49e9fb7ed525a5c5129f3cf4ee08fb708ab Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:53:09 -0300 Subject: [PATCH 08/25] fix: executable slice --- src/main/services/process-watcher.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index fda22a56..b9c26e42 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -59,7 +59,7 @@ const findGamePathByProcess = ( ); for (const executable of executables) { - const exe = getExecutable(executable.name); + const exe = executable.name.slice(executable.name.lastIndexOf("/")); if (!exe) continue; @@ -98,12 +98,6 @@ const getSystemProcessMap = async () => { return map; }; -const getExecutable = (path: string) => { - return path.slice( - path.lastIndexOf(process.platform === "win32" ? "\\" : "/") + 1 - ); -}; - export const watchProcesses = async () => { const gameIds = await gamesIdWithoutPath(); @@ -123,11 +117,15 @@ export const watchProcesses = async () => { if (!games.length) return; for (const game of games) { - if (!game.executablePath) continue; + const executablePath = game.executablePath; - const executable = getExecutable(game.executablePath); + if (!executablePath) continue; + + const executable = executablePath.slice( + executablePath.lastIndexOf(process.platform === "win32" ? "\\" : "/") + 1 + ); - const gameProcess = processMap.get(executable)?.has(game.executablePath); + const gameProcess = processMap.get(executable)?.has(executablePath); if (gameProcess) { if (gamesPlaytime.has(game.id)) { From fee1a927158da844bebb2614e5ad48a57345ffb6 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:10:34 -0300 Subject: [PATCH 09/25] fix: executable lastIndeOf --- src/main/services/process-watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index b9c26e42..2bdf82a9 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -59,7 +59,7 @@ const findGamePathByProcess = ( ); for (const executable of executables) { - const exe = executable.name.slice(executable.name.lastIndexOf("/")); + const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); if (!exe) continue; From 1ffb9828f7a3e7a9689ac0a8dfac564c992f3ff5 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:38:03 -0300 Subject: [PATCH 10/25] refactor: get system process map --- src/main/services/process-watcher.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 2bdf82a9..aa0959d3 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -88,11 +88,13 @@ const getSystemProcessMap = async () => { const map = new Map>(); processes.forEach((process) => { - const [key, value] = [process.name?.toLowerCase(), process.exe]; + const key = process.name.toLowerCase(); + const value = process.exe; if (!key || !value) return; - map.set(key, (map.get(key) ?? new Set()).add(value)); + const currentSet = map.get(key) ?? new Set(); + map.set(key, currentSet.add(value)); }); return map; From 431ad2ff2c98de4d3ed041bd9a771c134dc6272a Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:39:14 -0300 Subject: [PATCH 11/25] refactor: Set descontruction to Set foreach --- src/main/services/process-watcher.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index aa0959d3..28273281 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -63,19 +63,19 @@ const findGamePathByProcess = ( if (!exe) continue; - const hasProcess = processMap.get(exe); + const pathSet = processMap.get(exe); - if (hasProcess) { + if (pathSet) { const executableName = executable.name.replace(/\//g, "\\"); - for (const path of [...hasProcess]) { + pathSet.forEach((path) => { if (path.toLowerCase().endsWith(executableName)) { gameRepository.update( { objectID: id, shop: "steam" }, { executablePath: path } ); } - } + }); } } } From efcf778c9525eb9ce0d3ae837067052ed089c416 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:52:11 -0300 Subject: [PATCH 12/25] refactor: merged game queries to a single query --- src/main/services/process-watcher.ts | 83 +++++++++++----------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 28273281..2b7e6f9d 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -1,4 +1,3 @@ -import { IsNull, Not } from "typeorm"; import { gameRepository } from "@main/repository"; import { WindowManager } from "./window-manager"; import { createGame, updateGamePlaytime } from "./library-sync"; @@ -32,51 +31,33 @@ const gameExecutables = ( }) ).data as GameExecutables; -const gamesIdWithoutPath = async () => { - const games = await gameRepository.find({ - where: { - executablePath: IsNull(), - isDeleted: false, - }, - select: { - objectID: true, - }, - }); - - return games - .filter((game) => gameExecutables[game.objectID]) - .map((game) => game.objectID); -}; - const findGamePathByProcess = ( processMap: Map>, - gameIds: string[] + gameId: string ) => { - for (const id of gameIds) { - if (process.platform === "win32") { - const executables = gameExecutables[id].filter( - (info) => info.os === "win32" - ); - - for (const executable of executables) { - const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); - - if (!exe) continue; - - const pathSet = processMap.get(exe); - - if (pathSet) { - const executableName = executable.name.replace(/\//g, "\\"); - - pathSet.forEach((path) => { - if (path.toLowerCase().endsWith(executableName)) { - gameRepository.update( - { objectID: id, shop: "steam" }, - { executablePath: path } - ); - } - }); - } + if (process.platform === "win32") { + const executables = gameExecutables[gameId].filter( + (info) => info.os === "win32" + ); + + for (const executable of executables) { + const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); + + if (!exe) continue; + + const pathSet = processMap.get(exe); + + if (pathSet) { + const executableName = executable.name.replace(/\//g, "\\"); + + pathSet.forEach((path) => { + if (path.toLowerCase().endsWith(executableName)) { + gameRepository.update( + { objectID: gameId, shop: "steam" }, + { executablePath: path } + ); + } + }); } } } @@ -101,27 +82,25 @@ const getSystemProcessMap = async () => { }; export const watchProcesses = async () => { - const gameIds = await gamesIdWithoutPath(); - const games = await gameRepository.find({ where: { - executablePath: Not(IsNull()), isDeleted: false, }, }); - if (!games.length && !gameIds.length) return; + if (!games.length) return; const processMap = await getSystemProcessMap(); - findGamePathByProcess(processMap, gameIds); - - if (!games.length) return; - for (const game of games) { const executablePath = game.executablePath; - if (!executablePath) continue; + if (!executablePath) { + if (gameExecutables[game.objectID]) { + findGamePathByProcess(processMap, game.objectID); + } + continue; + } const executable = executablePath.slice( executablePath.lastIndexOf(process.platform === "win32" ? "\\" : "/") + 1 From 311b011ec61685e10c00b89515138e3745be91c1 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:48:07 -0300 Subject: [PATCH 13/25] feature: linux game observe --- src/main/services/process-watcher.ts | 58 +++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 2b7e6f9d..2922fcfb 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -5,6 +5,7 @@ import type { GameRunning } from "@types"; import { PythonInstance } from "./download"; import { Game } from "@main/entity"; import axios from "axios"; +import { exec } from "child_process"; export const gamesPlaytime = new Map< number, @@ -81,6 +82,18 @@ const getSystemProcessMap = async () => { return map; }; +const observeGameProcess = (hasProcess: boolean, game: Game) => { + if (hasProcess) { + if (gamesPlaytime.has(game.id)) { + onTickGame(game); + } else { + onOpenGame(game); + } + } else if (gamesPlaytime.has(game.id)) { + onCloseGame(game); + } +}; + export const watchProcesses = async () => { const games = await gameRepository.find({ where: { @@ -102,20 +115,45 @@ export const watchProcesses = async () => { continue; } - const executable = executablePath.slice( - executablePath.lastIndexOf(process.platform === "win32" ? "\\" : "/") + 1 - ); + const executable = executablePath + .slice( + executablePath.lastIndexOf(process.platform === "win32" ? "\\" : "/") + + 1 + ) + .toLowerCase(); + + const processSet = processMap.get(executable); + + if (!processSet) continue; - const gameProcess = processMap.get(executable)?.has(executablePath); + if (process.platform === "win32") { + const hasProcess = processSet.has(executablePath); - if (gameProcess) { - if (gamesPlaytime.has(game.id)) { - onTickGame(game); + observeGameProcess(hasProcess, game); + } + + 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 ""}\'`, + (err, out) => { + if (err) return; + + const pathSet = new Set( + out + .trim() + .split("\n") + .map((path) => path.trim()) + ); + + const hasProcess = pathSet.has(executablePath!); + + observeGameProcess(hasProcess, game); + } + ); } else { - onOpenGame(game); + //TODO: linux case } - } else if (gamesPlaytime.has(game.id)) { - onCloseGame(game); } } 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 14/25] 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; From 64745b9147455a48d3174a4591ac3abf08b54e0a Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:45:09 -0300 Subject: [PATCH 15/25] feature: linux find opened game and wine path --- src/main/services/process-watcher.ts | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 3fcc5269..2f2e2443 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -10,6 +10,8 @@ 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 ""}\'`, + findWineDir: () => + `lsof -c wine 2>/dev/null | grep -i drive_c/windows | head -n 1 | awk \'{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}\'`, }; export const gamesPlaytime = new Map< @@ -67,6 +69,75 @@ const findGamePathByProcess = ( } } } + + if (process.platform === "linux") { + const executables = gameExecutables[gameId].filter((info) => { + if (info.os === "win32") return true; + if (info.os === "linux") return true; + return false; + }); + + for (const executable of executables) { + if (executable.os === "win32") { + const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); + + if (!exe) return; + + const hasProcess = processMap.get(exe); + + if (hasProcess) { + new Promise((res) => { + exec( + commands.findGameExecutableWithWineProcess(exe), + (err, out) => { + if (err) { + res(false); + return; + } + + const paths = [ + ...new Set( + out + .trim() + .split("\n") + .map((path) => path.trim()) + ), + ]; + + for (const path of paths) { + if (path.toLocaleLowerCase().endsWith(executable.name)) { + gameRepository.update( + { objectID: gameId, shop: "steam" }, + { executablePath: path } + ); + + res(true); + return; + } + } + res(false); + } + ); + }).then((res) => { + if (res) { + exec(commands.findWineDir(), (err, out) => { + if (err) return; + + gameRepository.update( + { objectID: gameId, shop: "steam" }, + { + winePrefixPath: out.trim().replace("/drive_c/windows", ""), + } + ); + }); + } + }); + } + } else { + //TODO: linux case + } + } + } }; const getSystemProcessMap = async () => { From 9f8269d9a9f0f7ec229ab44ca6c4d12099a1d449 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:31:39 -0300 Subject: [PATCH 16/25] refactor: linux get game exe logic --- src/main/services/process-watcher.ts | 190 ++++++++++----------------- 1 file changed, 67 insertions(+), 123 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 2f2e2443..bd3252b6 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -8,10 +8,10 @@ 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 ""}\'`, findWineDir: () => - `lsof -c wine 2>/dev/null | grep -i drive_c/windows | head -n 1 | awk \'{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}\'`, + `lsof -c wine 2>/dev/null | grep '/drive_c/windows$' | head -n 1 | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, + findWineExecutables: () => + `lsof -c wine 2>/dev/null | grep '\.exe$' | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, }; export const gamesPlaytime = new Map< @@ -43,99 +43,45 @@ const findGamePathByProcess = ( processMap: Map>, gameId: string ) => { - if (process.platform === "win32") { - const executables = gameExecutables[gameId].filter( - (info) => info.os === "win32" - ); - - for (const executable of executables) { - const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); - - if (!exe) continue; - - const pathSet = processMap.get(exe); - - if (pathSet) { - const executableName = executable.name.replace(/\//g, "\\"); + const executables = gameExecutables[gameId].filter((info) => { + if (process.platform === "linux" && info.os === "linux") return true; + return info.os === "win32"; + }); - pathSet.forEach((path) => { - if (path.toLowerCase().endsWith(executableName)) { - gameRepository.update( - { objectID: gameId, shop: "steam" }, - { executablePath: path } - ); - } - }); - } - } - } + for (const executable of executables) { + const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); - if (process.platform === "linux") { - const executables = gameExecutables[gameId].filter((info) => { - if (info.os === "win32") return true; - if (info.os === "linux") return true; - return false; - }); + if (!exe) continue; - for (const executable of executables) { - if (executable.os === "win32") { - const exe = executable.name.slice(executable.name.lastIndexOf("/") + 1); + const pathSet = processMap.get(exe); - if (!exe) return; + if (pathSet) { + const executableName = + process.platform === "win32" + ? executable.name.replace(/\//g, "\\") + : executable.name; - const hasProcess = processMap.get(exe); + pathSet.forEach((path) => { + if (path.toLowerCase().endsWith(executableName)) { + gameRepository.update( + { objectID: gameId, shop: "steam" }, + { executablePath: path } + ); - if (hasProcess) { - new Promise((res) => { - exec( - commands.findGameExecutableWithWineProcess(exe), - (err, out) => { - if (err) { - res(false); - return; - } + if (process.platform === "linux") { + exec(commands.findWineDir(), (err, out) => { + if (err) return; - const paths = [ - ...new Set( - out - .trim() - .split("\n") - .map((path) => path.trim()) - ), - ]; - - for (const path of paths) { - if (path.toLocaleLowerCase().endsWith(executable.name)) { - gameRepository.update( - { objectID: gameId, shop: "steam" }, - { executablePath: path } - ); - - res(true); - return; - } + gameRepository.update( + { objectID: gameId, shop: "steam" }, + { + winePrefixPath: out.trim().replace("/drive_c/windows", ""), } - res(false); - } - ); - }).then((res) => { - if (res) { - exec(commands.findWineDir(), (err, out) => { - if (err) return; - - gameRepository.update( - { objectID: gameId, shop: "steam" }, - { - winePrefixPath: out.trim().replace("/drive_c/windows", ""), - } - ); - }); - } - }); + ); + }); + } } - } else { - //TODO: linux case - } + }); } } }; @@ -155,19 +101,35 @@ const getSystemProcessMap = async () => { map.set(key, currentSet.add(value)); }); - return map; -}; + if (process.platform === "linux") { + await new Promise((res) => { + exec(commands.findWineExecutables(), (err, out) => { + if (err) res(null); + + const pathSet = new Set( + out + .trim() + .split("\n") + .map((path) => path.trim()) + ); -const observeGameProcess = (hasProcess: boolean, game: Game) => { - if (hasProcess) { - if (gamesPlaytime.has(game.id)) { - onTickGame(game); - } else { - onOpenGame(game); - } - } else if (gamesPlaytime.has(game.id)) { - onCloseGame(game); + pathSet.forEach((path) => { + if (path.startsWith("/usr")) return; + + const key = path.slice(path.lastIndexOf("/") + 1).toLowerCase(); + + if (!key || !path) return; + + const currentSet = map.get(key) ?? new Set(); + map.set(key, currentSet.add(path)); + }); + + res(null); + }); + }); } + + return map; }; export const watchProcesses = async () => { @@ -202,34 +164,16 @@ export const watchProcesses = async () => { if (!processSet) continue; - if (process.platform === "win32") { - const hasProcess = processSet.has(executablePath); - - observeGameProcess(hasProcess, game); - } - - if (process.platform === "linux") { - if (executable.endsWith(".exe")) { - exec( - commands.findGameExecutableWithWineProcess(executable), - (err, out) => { - if (err) return; + const hasProcess = processSet.has(executablePath); - const pathSet = new Set( - out - .trim() - .split("\n") - .map((path) => path.trim()) - ); - - const hasProcess = pathSet.has(executablePath!); - - observeGameProcess(hasProcess, game); - } - ); + if (hasProcess) { + if (gamesPlaytime.has(game.id)) { + onTickGame(game); } else { - //TODO: linux case + onOpenGame(game); } + } else if (gamesPlaytime.has(game.id)) { + onCloseGame(game); } } From 66a8170fd21c66f6d51ab003b3ea669b0bb75a47 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:40:56 -0300 Subject: [PATCH 17/25] fix: lint --- src/main/services/process-watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index bd3252b6..7c33ca0f 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -11,7 +11,7 @@ const commands = { findWineDir: () => `lsof -c wine 2>/dev/null | grep '/drive_c/windows$' | head -n 1 | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, findWineExecutables: () => - `lsof -c wine 2>/dev/null | grep '\.exe$' | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, + `lsof -c wine 2>/dev/null | grep '\\.exe$' | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, }; export const gamesPlaytime = new Map< From f2714bd0aba1a8b8a0690e077f9832b72597f386 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:47:09 -0300 Subject: [PATCH 18/25] fix: process map promise return --- src/main/services/process-watcher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 7c33ca0f..90373cea 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -104,7 +104,10 @@ const getSystemProcessMap = async () => { if (process.platform === "linux") { await new Promise((res) => { exec(commands.findWineExecutables(), (err, out) => { - if (err) res(null); + if (err) { + res(null); + return; + } const pathSet = new Set( out From 347e38c41324d7014dcfded171100a97c7a054e9 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:35:42 -0300 Subject: [PATCH 19/25] refactor: move rpc game executables url to a env --- .github/workflows/build.yml | 2 ++ .github/workflows/release.yml | 2 ++ src/main/services/process-watcher.ts | 2 +- src/main/vite-env.d.ts | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0811967b..20d904c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,6 +50,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} - name: Build Windows if: matrix.os == 'windows-latest' @@ -62,6 +63,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} - name: Create artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b91cc743..c36b75d7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,6 +49,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} - name: Build Windows if: matrix.os == 'windows-latest' run: yarn build:win @@ -60,6 +61,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} - name: Create artifact uses: actions/upload-artifact@v4 with: diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 90373cea..6026527c 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -33,7 +33,7 @@ let currentTick = 1; const gameExecutables = ( await axios - .get("https://assets.hydralauncher.gg/game-executables.json") + .get(import.meta.env.MAIN_VITE_RPC_GAME_EXECUTABLES_URL) .catch(() => { return { data: {} }; }) diff --git a/src/main/vite-env.d.ts b/src/main/vite-env.d.ts index 86aa9d33..415250f0 100644 --- a/src/main/vite-env.d.ts +++ b/src/main/vite-env.d.ts @@ -6,6 +6,7 @@ interface ImportMetaEnv { readonly MAIN_VITE_ANALYTICS_API_URL: string; readonly MAIN_VITE_AUTH_URL: string; readonly MAIN_VITE_CHECKOUT_URL: string; + readonly MAIN_VITE_RPC_GAME_EXECUTABLES_URL: string; } interface ImportMeta { From 4c3eb98041ae56e9f1eb8fe66778e5855852ca4a Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:48:11 -0300 Subject: [PATCH 20/25] refactor: rpc url to a generic url --- .github/workflows/build.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- src/main/services/process-watcher.ts | 4 +++- src/main/vite-env.d.ts | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20d904c9..a94eef96 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} + MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} - name: Build Windows if: matrix.os == 'windows-latest' @@ -63,7 +63,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} + MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} - name: Create artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c36b75d7..e8396d71 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,7 +49,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} + MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} - name: Build Windows if: matrix.os == 'windows-latest' run: yarn build:win @@ -61,7 +61,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_RPC_GAME_EXECUTABLES_URL: ${{ vars.MAIN_VITE_RPC_GAME_EXECUTABLES_URL }} + MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} - name: Create artifact uses: actions/upload-artifact@v4 with: diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 6026527c..19b3bc85 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -33,7 +33,9 @@ let currentTick = 1; const gameExecutables = ( await axios - .get(import.meta.env.MAIN_VITE_RPC_GAME_EXECUTABLES_URL) + .get( + import.meta.env.MAIN_VITE_EXTERNAL_RESOURCES + "/game-executables.json" + ) .catch(() => { return { data: {} }; }) diff --git a/src/main/vite-env.d.ts b/src/main/vite-env.d.ts index 415250f0..95e1e545 100644 --- a/src/main/vite-env.d.ts +++ b/src/main/vite-env.d.ts @@ -6,7 +6,7 @@ interface ImportMetaEnv { readonly MAIN_VITE_ANALYTICS_API_URL: string; readonly MAIN_VITE_AUTH_URL: string; readonly MAIN_VITE_CHECKOUT_URL: string; - readonly MAIN_VITE_RPC_GAME_EXECUTABLES_URL: string; + readonly MAIN_VITE_EXTERNAL_RESOURCES: string; } interface ImportMeta { From e95407e6f5bd043162fa695fdd4cebc6d304586c Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:51:22 -0300 Subject: [PATCH 21/25] refactor: add URL to end of the env main external resources --- .github/workflows/build.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- src/main/services/process-watcher.ts | 3 ++- src/main/vite-env.d.ts | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a94eef96..8776f630 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} + MAIN_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES_URL }} - name: Build Windows if: matrix.os == 'windows-latest' @@ -63,7 +63,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} + MAIN_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES_URL }} - name: Create artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e8396d71..2f1d3188 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,7 +49,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} + MAIN_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES_URL }} - name: Build Windows if: matrix.os == 'windows-latest' run: yarn build:win @@ -61,7 +61,7 @@ jobs: RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }} RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MAIN_VITE_EXTERNAL_RESOURCES: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES }} + MAIN_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES_URL }} - name: Create artifact uses: actions/upload-artifact@v4 with: diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 19b3bc85..fcb0197e 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -34,7 +34,8 @@ let currentTick = 1; const gameExecutables = ( await axios .get( - import.meta.env.MAIN_VITE_EXTERNAL_RESOURCES + "/game-executables.json" + import.meta.env.MAIN_VITE_EXTERNAL_RESOURCES_URL + + "/game-executables.json" ) .catch(() => { return { data: {} }; diff --git a/src/main/vite-env.d.ts b/src/main/vite-env.d.ts index 95e1e545..af40cf5f 100644 --- a/src/main/vite-env.d.ts +++ b/src/main/vite-env.d.ts @@ -6,7 +6,7 @@ interface ImportMetaEnv { readonly MAIN_VITE_ANALYTICS_API_URL: string; readonly MAIN_VITE_AUTH_URL: string; readonly MAIN_VITE_CHECKOUT_URL: string; - readonly MAIN_VITE_EXTERNAL_RESOURCES: string; + readonly MAIN_VITE_EXTERNAL_RESOURCES_URL: string; } interface ImportMeta { From 1f3a6a9da6375af88d4c4e33138c4de5b0efbd1f Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:20:07 -0300 Subject: [PATCH 22/25] refactor: add bundle.js in external script environment --- src/renderer/src/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 1ec7507e..8ed51d93 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -126,7 +126,7 @@ export function App() { const $script = document.createElement("script"); $script.id = "external-resources"; - $script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}?t=${Date.now()}`; + $script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL + "/bundle.js"}?t=${Date.now()}`; document.head.appendChild($script); }); }, [fetchUserDetails, syncFriendRequests, updateUserDetails, dispatch]); From 5222d319a345f3cd7b15a547fbd8c60e2419ccd4 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:25:55 -0300 Subject: [PATCH 23/25] refactor: add bundle.js in external script environment --- src/renderer/src/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 8ed51d93..422e5192 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -126,7 +126,7 @@ export function App() { const $script = document.createElement("script"); $script.id = "external-resources"; - $script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL + "/bundle.js"}?t=${Date.now()}`; + $script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}/bundle.js?t=${Date.now()}`; document.head.appendChild($script); }); }, [fetchUserDetails, syncFriendRequests, updateUserDetails, dispatch]); From 4f7255a8d9d85e642242d681c270d87836bb9e20 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:31:12 -0300 Subject: [PATCH 24/25] refactor: process watcher commands --- src/main/services/process-watcher.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index fcb0197e..abce6ae4 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -8,10 +8,8 @@ import axios from "axios"; import { exec } from "child_process"; const commands = { - findWineDir: () => - `lsof -c wine 2>/dev/null | grep '/drive_c/windows$' | head -n 1 | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, - findWineExecutables: () => - `lsof -c wine 2>/dev/null | grep '\\.exe$' | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, + findWineDir: `lsof -c wine 2>/dev/null | grep '/drive_c/windows$' | head -n 1 | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, + findWineExecutables: `lsof -c wine 2>/dev/null | grep '\\.exe$' | awk '{for(i=9;i<=NF;i++) printf "%s ", $i; print ""}'`, }; export const gamesPlaytime = new Map< @@ -72,7 +70,7 @@ const findGamePathByProcess = ( ); if (process.platform === "linux") { - exec(commands.findWineDir(), (err, out) => { + exec(commands.findWineDir, (err, out) => { if (err) return; gameRepository.update( @@ -106,7 +104,7 @@ const getSystemProcessMap = async () => { if (process.platform === "linux") { await new Promise((res) => { - exec(commands.findWineExecutables(), (err, out) => { + exec(commands.findWineExecutables, (err, out) => { if (err) { res(null); return; From bc98f7c55e45d8a86160c2d5ddeb3ff94dd80413 Mon Sep 17 00:00:00 2001 From: JackEnx <167036558+JackEnx@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:02:13 -0300 Subject: [PATCH 25/25] fix: closed game pestis in the watch processes --- src/main/services/process-watcher.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index abce6ae4..b95b93cf 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -164,11 +164,7 @@ export const watchProcesses = async () => { ) .toLowerCase(); - const processSet = processMap.get(executable); - - if (!processSet) continue; - - const hasProcess = processSet.has(executablePath); + const hasProcess = processMap.get(executable)?.has(executablePath); if (hasProcess) { if (gamesPlaytime.has(game.id)) {