From d4aebf7d99c89196730d7d3c8e9b1d1ef44b6983 Mon Sep 17 00:00:00 2001 From: discollizard Date: Sat, 22 Jun 2024 12:59:17 -0300 Subject: [PATCH 1/2] clicking 'play' now redirects to the same folder as the installer --- .../game-details/game-details.context.tsx | 5 +++-- .../game-details.context.types.ts | 2 +- .../game-details/hero/hero-panel-actions.tsx | 22 +++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/context/game-details/game-details.context.tsx b/src/renderer/src/context/game-details/game-details.context.tsx index ad32f987..64d67106 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -131,8 +131,9 @@ export function GameDetailsContextProvider({ return window.electron.getDefaultDownloadsPath(); }; - const selectGameExecutable = async () => { - const downloadsPath = await getDownloadsPath(); + const selectGameExecutable = async (gameInstallerFolderIfExists: string | null) => { + + const downloadsPath = gameInstallerFolderIfExists ?? await getDownloadsPath(); return window.electron .showOpenDialog({ diff --git a/src/renderer/src/context/game-details/game-details.context.types.ts b/src/renderer/src/context/game-details/game-details.context.types.ts index 36e55a79..e1551e34 100644 --- a/src/renderer/src/context/game-details/game-details.context.types.ts +++ b/src/renderer/src/context/game-details/game-details.context.types.ts @@ -13,7 +13,7 @@ export interface GameDetailsContext { showRepacksModal: boolean; showGameOptionsModal: boolean; setGameColor: React.Dispatch>; - selectGameExecutable: () => Promise; + selectGameExecutable: (gameInstallerFolderIfExists: string | null) => Promise; updateGame: () => Promise; setShowRepacksModal: React.Dispatch>; setShowGameOptionsModal: React.Dispatch>; diff --git a/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx b/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx index 4741668e..e065d5c2 100644 --- a/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx +++ b/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx @@ -1,6 +1,6 @@ import { GearIcon, PlayIcon, PlusCircleIcon } from "@primer/octicons-react"; import { Button } from "@renderer/components"; -import { useDownload, useLibrary } from "@renderer/hooks"; +import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks"; import { useContext, useState } from "react"; import { useTranslation } from "react-i18next"; import * as styles from "./hero-panel-actions.css"; @@ -13,6 +13,10 @@ export function HeroPanelActions() { const { isGameDeleting } = useDownload(); + const userPreferences = useAppSelector( + (state) => state.userPreferences.value + ); + const { game, repacks, @@ -49,7 +53,21 @@ export function HeroPanelActions() { return; } - const gameExecutablePath = await selectGameExecutable(); + let gameInstallerFolderIfExists: string | null = null + + if (game && game.folderName){ + let downloadsPath = await window.electron.getDefaultDownloadsPath(); + if (userPreferences?.downloadsPath) + downloadsPath = userPreferences.downloadsPath; + + const folderSeparator = window.electron.platform == 'win32' + ? '\\' + : '/' + + gameInstallerFolderIfExists = (game.downloadPath ?? downloadsPath)+folderSeparator+game.folderName! + } + + const gameExecutablePath = await selectGameExecutable(gameInstallerFolderIfExists); if (gameExecutablePath) window.electron.openGame(game.id, gameExecutablePath); } From ea412c64c3cda18eab3cfffe0e4b3d5f56c36eb1 Mon Sep 17 00:00:00 2001 From: discollizard Date: Sat, 22 Jun 2024 13:19:35 -0300 Subject: [PATCH 2/2] fixed function arguments --- .../game-details/game-details.context.tsx | 8 +++++--- .../game-details/game-details.context.types.ts | 4 +++- .../game-details/hero/hero-panel-actions.tsx | 18 +++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/context/game-details/game-details.context.tsx b/src/renderer/src/context/game-details/game-details.context.tsx index 64d67106..aedd315d 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -131,9 +131,11 @@ export function GameDetailsContextProvider({ return window.electron.getDefaultDownloadsPath(); }; - const selectGameExecutable = async (gameInstallerFolderIfExists: string | null) => { - - const downloadsPath = gameInstallerFolderIfExists ?? await getDownloadsPath(); + const selectGameExecutable = async ( + gameInstallerFolderIfExists?: string + ) => { + const downloadsPath = + gameInstallerFolderIfExists ?? (await getDownloadsPath()); return window.electron .showOpenDialog({ diff --git a/src/renderer/src/context/game-details/game-details.context.types.ts b/src/renderer/src/context/game-details/game-details.context.types.ts index e1551e34..d4af8192 100644 --- a/src/renderer/src/context/game-details/game-details.context.types.ts +++ b/src/renderer/src/context/game-details/game-details.context.types.ts @@ -13,7 +13,9 @@ export interface GameDetailsContext { showRepacksModal: boolean; showGameOptionsModal: boolean; setGameColor: React.Dispatch>; - selectGameExecutable: (gameInstallerFolderIfExists: string | null) => Promise; + selectGameExecutable: ( + gameInstallerFolderIfExists?: string + ) => Promise; updateGame: () => Promise; setShowRepacksModal: React.Dispatch>; setShowGameOptionsModal: React.Dispatch>; diff --git a/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx b/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx index e065d5c2..451b610c 100644 --- a/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx +++ b/src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx @@ -53,21 +53,25 @@ export function HeroPanelActions() { return; } - let gameInstallerFolderIfExists: string | null = null + let gameInstallerFolderIfExists - if (game && game.folderName){ + if (game && game.folderName) { let downloadsPath = await window.electron.getDefaultDownloadsPath(); if (userPreferences?.downloadsPath) downloadsPath = userPreferences.downloadsPath; - const folderSeparator = window.electron.platform == 'win32' - ? '\\' - : '/' + const folderSeparator = + window.electron.platform == "win32" ? "\\" : "/"; - gameInstallerFolderIfExists = (game.downloadPath ?? downloadsPath)+folderSeparator+game.folderName! + gameInstallerFolderIfExists = + (game.downloadPath ?? downloadsPath) + + folderSeparator + + game.folderName!; } - const gameExecutablePath = await selectGameExecutable(gameInstallerFolderIfExists); + const gameExecutablePath = await selectGameExecutable( + gameInstallerFolderIfExists + ); if (gameExecutablePath) window.electron.openGame(game.id, gameExecutablePath); }