A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
import { faSpinner } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
GameInfo,
InstallPlatform,
Runner,
WineInstallation
} from 'common/types'
import { PathSelectionBox } from 'frontend/components/UI'
import {
ModalHeader,
ModalFooter,
ModalContent
} from 'frontend/components/UI/Modal'
import Button from 'frontend/components/UI/Button'
import ContextProvider from 'frontend/state/ContextProvider'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { AvailablePlatforms } from '../index'
import { configStore } from 'frontend/helpers/electronStores'
interface Props {
backdropClick: () => void
appName: string
runner: Runner
platformToInstall: InstallPlatform
availablePlatforms: AvailablePlatforms
winePrefix: string
crossoverBottle: string
wineVersion: WineInstallation | undefined
children: React.ReactNode
gameInfo: GameInfo
}
const userHome = configStore.get('userHome', '')
function getDefaultInstallPath() {
const { defaultInstallPath = `${userHome}/Games/Heroic` } = {
...configStore.get_nodefault('settings')
}
return defaultInstallPath
}
export default function ImportDialog({
backdropClick,
appName,
runner,
platformToInstall,
availablePlatforms,
winePrefix,
wineVersion,
crossoverBottle,
children,
gameInfo
}: Props) {
const { libraryStatus } = useContext(ContextProvider)
const { t } = useTranslation('gamepage')
const [importPath, setImportPath] = React.useState('')
const title = gameInfo?.title
const isImportingThisGame = libraryStatus.some(
(game) => game.appName === appName && game.status === 'importing'
)
const pickFile = platformToInstall === 'Mac'
async function handleImport() {
if (!importPath) return
backdropClick()
await window.api.importGame({
appName,
path: importPath,
runner,
platform: platformToInstall,
winePrefix,
wineVersion,
wineCrossoverBottle: crossoverBottle
})
}
return (
<>
<ModalHeader>
{title ? title : '...'}
{availablePlatforms.map((p) => (
<FontAwesomeIcon
className="InstallModal__platformIcon"
icon={p.icon}
key={p.value}
/>
))}
</ModalHeader>
<ModalContent>
<PathSelectionBox
type={pickFile ? 'file' : 'directory'}
onPathChange={setImportPath}
path={importPath}
placeholder={getDefaultInstallPath()}
pathDialogTitle={t('box.importpath', 'Select Folder to Import')}
pathDialogDefaultPath={getDefaultInstallPath()}
htmlId="setimportpath"
label={t('install.path', 'Select Install Path')}
noDeleteButton
/>
{runner === 'itchio' && (
<span className="warning">
{t(
'itchio.import.warning',
'Folders installed by the itch.io app are fully imported, including updates. For any other folder, Heroic cannot check for updates and uninstalling will not delete the game files.'
)}
</span>
)}
{children}
</ModalContent>
<ModalFooter>
<Button
onClick={handleImport}
disabled={!importPath || isImportingThisGame}
icon={
isImportingThisGame ? (
<FontAwesomeIcon className="fa-spin-pulse" icon={faSpinner} />
) : null
}
>
{t('button.import', 'Import')}
</Button>
</ModalFooter>
</>
)
}