import { NoEntryIcon, PlusCircleIcon } from "@primer/octicons-react"; import { Button } from "@renderer/components"; import { useDownload, useLibrary } from "@renderer/hooks"; import type { Game, ShopDetails } from "@types"; import { useState } from "react"; import { useTranslation } from "react-i18next"; export interface HeroPanelActionsProps { game: Game | null; gameDetails: ShopDetails | null; isGamePlaying: boolean; isGameDownloading: boolean; openRepacksModal: () => void; openBinaryNotFoundModal: () => void; getGame: () => void; } export function HeroPanelActions({ game, gameDetails, isGamePlaying, isGameDownloading, openRepacksModal, openBinaryNotFoundModal, getGame, }: HeroPanelActionsProps) { const [toggleLibraryGameDisabled, setToggleLibraryGameDisabled] = useState(false); const { resumeDownload, pauseDownload, cancelDownload, removeGameFromDownload, isGameDeleting, } = useDownload(); const { updateLibrary, removeGameFromLibrary } = useLibrary(); const { t } = useTranslation("game_details"); const selectGameExecutable = async () => { return window.electron .showOpenDialog({ properties: ["openFile"], filters: [ { name: "Game executable", extensions: window.electron.platform === "win32" ? ["exe"] : [], }, ], }) .then(({ filePaths }) => { if (filePaths && filePaths.length > 0) { return filePaths[0]; } }); }; const toggleGameOnLibrary = async () => { setToggleLibraryGameDisabled(true); try { if (game) { await removeGameFromLibrary(game.id); } else { const gameExecutablePath = await selectGameExecutable(); await window.electron.addGameToLibrary( gameDetails.objectID, gameDetails.name, "steam", gameExecutablePath ); } updateLibrary(); getGame(); } finally { setToggleLibraryGameDisabled(false); } }; const openGameInstaller = () => { window.electron.openGameInstaller(game.id).then((isBinaryInPath) => { if (!isBinaryInPath) openBinaryNotFoundModal(); updateLibrary(); }); }; const openGame = async () => { if (game.executablePath) { window.electron.openGame(game.id, game.executablePath); return; } if (game?.executablePath) { window.electron.openGame(game.id, game.executablePath); return; } const gameExecutablePath = await selectGameExecutable(); if (!gameExecutablePath) return; window.electron.openGame(game.id, gameExecutablePath); }; const closeGame = () => window.electron.closeGame(game.id); const deleting = isGameDeleting(game?.id); const toggleGameOnLibraryButton = ( ); if (isGameDownloading) { return ( <> ); } if (game?.status === "paused") { return ( <> ); } if (game?.status === "seeding" || (game && !game.status)) { return ( <> {game?.status === "seeding" ? ( ) : ( toggleGameOnLibraryButton )} {isGamePlaying ? ( ) : ( )} ); } if (game?.status === "cancelled") { return ( <> ); } if (gameDetails && gameDetails.repacks.length) { return ( <> {toggleGameOnLibraryButton} ); } return toggleGameOnLibraryButton; }