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 {
CircleCheck,
LoaderCircle,
MonitorDown,
Search,
TriangleAlert
} from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Alert, Icon, LogPanel, ProgressBar } from 'frontend/components/UI'
import Button from 'frontend/components/UI/Button'
import useInstallerLog from '../hooks/useInstallerLog'
export type PresetInstallPhase =
| 'idle'
| 'downloading'
| 'running'
| 'detecting'
| 'done'
| 'error'
type Props = {
appName: string
presetTitle: string
phase: PresetInstallPhase
downloadProgress: number
error?: string
onContinue: () => void
onRetry: () => void
onCheckAgain: () => void
onSelectManually: () => void
onCancel: () => void
canRetryInteractive: boolean
onRetryInteractive: () => void
showInstallerNotice?: boolean
}
export default function PresetInstallStep({
appName,
presetTitle,
phase,
downloadProgress,
error,
onContinue,
onRetry,
onCheckAgain,
onSelectManually,
onCancel,
canRetryInteractive,
onRetryInteractive,
showInstallerNotice = false
}: Props) {
const { t } = useTranslation('gamepage')
const logContent = useInstallerLog(appName, phase === 'running')
const cancelButton = (
<Button variant="ghost" onClick={onCancel}>
{t('sideload.presets.cancel', 'Cancel')}
</Button>
)
if (phase === 'done') {
return (
<div className="sideloadPresetInstall">
<div className="sideloadPresetInstall__status">
<Icon glyph={CircleCheck} size="lg" />
<span>
{t(
'sideload.presets.done',
'Executable found, you can finish the setup.'
)}
</span>
</div>
<p className="sideloadPresetInstall__hint">
{t(
'sideload.presets.next-steps',
'Open {{title}}, sign in, install a game there, then return to this page and use "Scan games" to add it to Heroic.',
{ title: presetTitle }
)}
</p>
</div>
)
}
if (phase === 'error') {
const notFound = error === 'not-found'
return (
<div className="sideloadPresetInstall">
<Alert
variant="error"
title={
notFound
? t(
'sideload.presets.not-found.title',
"We couldn't find the installed app"
)
: t('sideload.presets.error.title', 'Something went wrong')
}
>
{notFound
? t(
'sideload.presets.not-found.description',
"The installer finished, but Heroic couldn't locate {{title}} in the Wine prefix. You can try again, or select the executable manually.",
{ title: presetTitle }
)
: t(
'sideload.presets.error.description',
'Heroic could not finish setting up {{title}}. You can try again or select the executable manually.',
{ title: presetTitle }
)}
{!notFound && error ? (
<span className="sideloadPresetInstall__errorDetail">{error}</span>
) : null}
</Alert>
<div className="sideloadPresetInstall__actions">
{notFound ? (
<Button variant="primary" onClick={onCheckAgain}>
{t('sideload.presets.check-again', 'Check again')}
</Button>
) : (
<Button variant="secondary" onClick={onRetry}>
{t('sideload.presets.retry', 'Try again')}
</Button>
)}
<Button
variant={notFound ? 'secondary' : 'primary'}
onClick={onSelectManually}
>
{t(
'sideload.presets.select-manually',
'Select executable manually'
)}
</Button>
{canRetryInteractive && (
<Button variant="ghost" onClick={onRetryInteractive}>
{t(
'sideload.presets.retry-interactive',
'Run installer interactively'
)}
</Button>
)}
{cancelButton}
</div>
</div>
)
}
if (phase === 'downloading') {
return (
<div className="sideloadPresetInstall">
<div className="sideloadPresetInstall__status">
<Icon glyph={MonitorDown} size="lg" />
<span>
{t('sideload.presets.downloading', 'Downloading the installer…')}
</span>
</div>
<ProgressBar
value={downloadProgress}
showValue
size="md"
label={t(
'sideload.presets.downloading',
'Downloading the installer…'
)}
/>
<p className="sideloadPresetInstall__hint">
{t(
'sideload.presets.downloading-hint',
'Heroic downloads {{title}} directly from the official vendor endpoint. Nothing is bundled with the app.',
{ title: presetTitle }
)}
</p>
<div className="sideloadPresetInstall__actions">{cancelButton}</div>
</div>
)
}
if (phase === 'detecting') {
return (
<div className="sideloadPresetInstall">
<div className="sideloadPresetInstall__status">
<Icon glyph={Search} size="lg" />
<span>
{t(
'sideload.presets.detecting',
'Looking for the installed application…'
)}
</span>
</div>
<div className="sideloadPresetInstall__actions">{cancelButton}</div>
</div>
)
}
if (phase === 'running') {
return (
<div className="sideloadPresetInstall sideloadPresetInstall--running">
<div className="sideloadPresetInstall__status">
<Icon glyph={LoaderCircle} size="lg" className="spinner" />
<span>
{t(
'sideload.presets.running.title',
'Complete the {{title}} installation',
{ title: presetTitle }
)}
</span>
</div>
<p className="sideloadPresetInstall__hint">
{t(
'sideload.presets.running.description',
'Finish the installer in the window that just opened. If the installer launches {{title}} at the end, close it so Heroic can continue. You can also continue now and pick the executable manually.',
{ title: presetTitle }
)}
</p>
{showInstallerNotice && (
<Alert variant="warning" className="sideloadPresetNote">
{t(
'sideload.presets.macos-installer-notice',
"macOS: the installer starts {{title}} at the end. That window can stay blank because the installer doesn't use Heroic's graphics settings. Close it, finish the setup, and start {{title}} from Heroic.",
{ title: presetTitle }
)}
</Alert>
)}
<div className="sideloadPresetInstall__actions">
<Button variant="secondary" onClick={onContinue}>
{t('sideload.presets.continue', 'Continue anyway')}
</Button>
{cancelButton}
</div>
<div className="sideloadPresetInstall__log">
{logContent ? (
<LogPanel content={logContent} />
) : (
<span className="sideloadPresetInstall__logPlaceholder">
{t(
'sideload.presets.running.waiting-log',
'Waiting for installer output…'
)}
</span>
)}
</div>
</div>
)
}
return (
<div className="sideloadPresetInstall">
<div className="sideloadPresetInstall__status">
<Icon glyph={TriangleAlert} size="lg" />
<span>
{t('sideload.presets.preparing', 'Preparing the installer…')}
</span>
</div>
<div className="sideloadPresetInstall__actions">{cancelButton}</div>
</div>
)
}