Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

26.8 KB
Raw Blame
import './index.scss'
import short from 'short-uuid'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
  InstallPlatform,
  WineInstallation,
  GameInfo,
  GameSettings,
  EnviromentVariable
} from 'common/types'
import {
  getSideloadPresetAppName,
  getSideloadPresetText,
  type SideloadPreset,
  type SideloadPresetPlatform
} from 'common/sideload_presets'
import { ModalContent, ModalFooter } from 'frontend/components/UI/Modal'
import Button from 'frontend/components/UI/Button'
import {
  Alert,
  Stepper,
  StepperStep,
  ToggleSwitch
} from 'frontend/components/UI'
import { getGameInfo, getGameSettings, writeConfig } from 'frontend/helpers'
import React, {
  useCallback,
  useContext,
  useEffect,
  useMemo,
  useRef,
  useState
} from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { AvailablePlatforms } from '..'
import fallbackImage from 'frontend/assets/heroic_card.jpg'
import ContextProvider from 'frontend/state/ContextProvider'
import MetadataStep from './steps/MetadataStep'
import InstallationStep from './steps/InstallationStep'
import FinishStep from './steps/FinishStep'
import ImagesStep from './steps/ImagesStep'
import PresetInstallStep, {
  type PresetInstallPhase
} from './steps/PresetInstallStep'
import SideloadAdvanced from '../SideloadAdvanced'
import Winetricks from 'frontend/components/UI/Winetricks'

type Props = {
  availablePlatforms: AvailablePlatforms
  winePrefix: string
  crossoverBottle: string
  wineVersion: WineInstallation | undefined
  wineSelectionValid: boolean
  platformToInstall: InstallPlatform
  platformSelection: React.ReactNode
  wineSelector?: React.ReactNode
  backdropClick: () => void
  appName?: string
  title: string
  setTitle: (title: string) => void
  preset?: SideloadPreset
  onBackToPresets?: () => void
  onPresetBusyChange?: (busy: boolean) => void
}

type SupportedSteps = 'meta' | 'images' | 'compat' | 'install' | 'finish'

export default function SideloadDialog({
  availablePlatforms,
  backdropClick,
  winePrefix,
  crossoverBottle,
  wineVersion,
  wineSelectionValid,
  platformToInstall,
  platformSelection,
  wineSelector,
  appName,
  title,
  setTitle,
  preset,
  onBackToPresets,
  onPresetBusyChange
}: Props) {
  const { t } = useTranslation('gamepage')
  const navigate = useNavigate()
  const [activeStep, setActiveStep] = useState(0)
  const [selectedExe, setSelectedExe] = useState('')
  const [gameUrl, setGameUrl] = useState('')
  const [customUserAgent, setCustomUserAgent] = useState('')
  const [launchFullScreen, setLaunchFullScreen] = useState(false)
  const [imageUrl, setImageUrl] = useState('')
  const [heroUrl, setHeroUrl] = useState('')
  const [app_name, setApp_name] = useState(
    preset ? getSideloadPresetAppName(preset) : (appName ?? '')
  )
  const [runningSetup, setRunningSetup] = useState(false)
  const [gameInfo, setGameInfo] = useState<Partial<GameInfo>>({})
  const [addingApp, setAddingApp] = useState(false)
  const [hasSgdbKey, setHasSgdbKey] = useState(false)
  const [environmentOptions, setEnvironmentOptions] = useState<
    EnviromentVariable[]
  >([])
  const [umuGameId, setUmuGameId] = useState('')
  const [winetricksOpen, setWinetricksOpen] = useState(false)
  const [presetPhase, setPresetPhase] = useState<PresetInstallPhase>('idle')
  const [installSilently, setInstallSilently] = useState(true)
  const [presetDownloadProgress, setPresetDownloadProgress] = useState(0)
  const [presetError, setPresetError] = useState('')
  const editMode = Boolean(appName)
  const presetStarted = useRef(false)
  const presetRunId = useRef(0)

  const { refreshLibrary, platform, showDialogModal } =
    useContext(ContextProvider)

  const appPlatform = gameInfo.install?.platform || platformToInstall
  const activePresetId = preset?.id
  const presetText = preset ? getSideloadPresetText(t, preset) : undefined

  const withAdvancedSettings = useCallback(
    (settings: GameSettings): GameSettings => ({
      ...settings,
      winePrefix,
      wineVersion: wineVersion || settings.wineVersion,
      wineCrossoverBottle: crossoverBottle,
      ...(environmentOptions.length
        ? { enviromentOptions: environmentOptions }
        : {}),
      ...(umuGameId.trim() ? { umuGameId } : {})
    }),
    [winePrefix, wineVersion, crossoverBottle, environmentOptions, umuGameId]
  )

  const getConfigOverride = useCallback(
    (settings: GameSettings): Partial<GameSettings> => {
      // Only write per-game values the user explicitly set. Empty values must
      // inherit the global configuration instead of freezing it.
      const advanced = Object.fromEntries(
        Object.entries(settings).filter(
          ([key]) => key !== 'enviromentOptions' && key !== 'umuGameId'
        )
      ) as Partial<GameSettings>

      return {
        ...advanced,
        ...(environmentOptions.length
          ? { enviromentOptions: environmentOptions }
          : {}),
        ...(umuGameId.trim() ? { umuGameId } : {})
      }
    },
    [environmentOptions, umuGameId]
  )

  const perGameSettings = useMemo(
    () => ({
      winePrefix,
      wineVersion,
      wineCrossoverBottle: crossoverBottle,
      ...(environmentOptions.length
        ? { enviromentOptions: environmentOptions }
        : {}),
      ...(umuGameId.trim() ? { umuGameId } : {})
    }),
    [winePrefix, wineVersion, crossoverBottle, environmentOptions, umuGameId]
  )

  useEffect(() => {
    void window.api.steamgriddb.hasApiKey().then(setHasSgdbKey)

    if (appName) {
      void getGameInfo(appName, 'sideload').then((info) => {
        if (!info || info.runner !== 'sideload') {
          return
        }
        setGameInfo(info)
        const {
          art_cover,
          art_square,
          install: { executable, platform },
          title,
          browserUrl,
          customUserAgent,
          launchFullScreen
        } = info

        if (executable && platform) {
          setSelectedExe(executable)
        }

        if (browserUrl) {
          setGameUrl(browserUrl)
        }

        if (customUserAgent) {
          setCustomUserAgent(customUserAgent)
        }

        if (launchFullScreen !== undefined) {
          setLaunchFullScreen(launchFullScreen)
        }

        setTitle(title)
        setImageUrl(art_square || '')
        setHeroUrl(art_cover && art_cover !== art_square ? art_cover : '')
      })
      return
    }

    if (preset) {
      setApp_name(getSideloadPresetAppName(preset))
      if (preset.web) {
        setGameUrl(preset.web.url)
        setCustomUserAgent(preset.web.userAgent ?? '')
        setLaunchFullScreen(preset.web.launchFullScreen ?? false)
      }
      return
    }

    setApp_name(short.generate().toString())
    // Only run on mount: the dialog is remounted for every new app/preset.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  useEffect(() => {
    if (!activePresetId || appName) {
      return
    }

    let active = true
    window.api
      .getSideloadPresetArtwork(activePresetId)
      .then(({ square, hero }) => {
        if (!active) {
          return
        }
        setImageUrl(square)
        setHeroUrl(hero)
      })
      .catch(() => {})

    return () => {
      active = false
    }
  }, [activePresetId, appName])

  useEffect(() => {
    if (!activePresetId) {
      return
    }

    return window.api.onPresetDownloadProgress((_, { presetId, progress }) => {
      if (presetId === activePresetId) {
        setPresetDownloadProgress(progress)
      }
    })
  }, [activePresetId])

  useEffect(
    () => () => {
      // Invalidate any download/install chain that is still in flight when
      // the dialog closes.
      presetRunId.current++
    },
    []
  )

  async function handleInstall(): Promise<void> {
    if (!wineSelectionValid) return

    setAddingApp(true)
    window.api.addNewApp({
      runner: 'sideload',
      app_name,
      title,
      install: {
        executable: selectedExe,
        platform: gameInfo.install?.platform ?? platformToInstall
      },
      art_cover: heroUrl || imageUrl || fallbackImage,
      is_installed: true,
      art_square: imageUrl || heroUrl || fallbackImage,
      canRunOffline: true,
      browserUrl: gameUrl,
      customUserAgent,
      launchFullScreen,
      presetId: preset?.id
    })

    if (!editMode) {
      await window.api.writeConfig({
        appName: app_name,
        config: perGameSettings
      })
    }

    await refreshLibrary({
      library: 'sideload',
      runInBackground: true,
      checkForUpdates: true
    })
    setAddingApp(false)

    // When a launcher preset is added, check right away whether the prefix
    // already contains games. If it does, take the user to the launcher page
    // with the scan dialog open; if not, just close without an empty dialog.
    if (preset?.kind === 'launcher' && !editMode) {
      try {
        const scan = await window.api.scanSideloadPresetGames(preset.id)
        if (scan.games.length > 0) {
          const info = await window.api.getGameInfo(app_name, 'sideload')
          if (info) {
            backdropClick()
            navigate(`/gamepage/sideload/${app_name}`, {
              state: { gameInfo: info, autoScanGames: true }
            })
            return
          }
        }
      } catch (scanError) {
        window.api.logError(String(scanError))
      }
    }

    return backdropClick()
  }

  const fileFilters = useCallback((platform: InstallPlatform) => {
    switch (platform) {
      case 'Windows':
      case 'windows':
      case 'Win32':
        return [
          { name: 'Executables', extensions: ['exe', 'msi'] },
          { name: 'Scripts', extensions: ['bat'] },
          { name: 'All', extensions: ['*'] }
        ]
      case 'linux':
        return [
          { name: 'AppImages', extensions: ['AppImage'] },
          { name: 'Other Binaries', extensions: ['sh', 'py', 'bin'] },
          { name: 'All', extensions: ['*'] }
        ]
      case 'osx':
      case 'Mac':
        return [
          { name: 'Apps', extensions: ['App'] },
          { name: 'Other Binaries', extensions: ['sh', 'py', 'bin'] },
          { name: 'All', extensions: ['*'] }
        ]
      // FIXME: Can these happen?
      case 'Android':
      case 'iOS':
      case 'Browser':
        return []
    }
  }, [])

  const handleRunExe = async () => {
    let exeToRun = ''
    const path = await window.api.openDialog({
      buttonLabel: t('box.select.button', 'Select'),
      properties: ['openFile'],
      title: t('box.runexe.title', 'Select EXE to Run'),
      filters: fileFilters(appPlatform)
    })
    if (path) {
      exeToRun = path
      try {
        setRunningSetup(true)
        const gameSettings = await getGameSettings(app_name, 'sideload')
        if (!gameSettings) {
          return
        }
        const settingsWithAdvanced = withAdvancedSettings(gameSettings)
        await writeConfig({
          appName: app_name,
          config: getConfigOverride(settingsWithAdvanced)
        })
        await window.api.runWineCommand({
          commandParts: [exeToRun],
          wait: true,
          protonVerb: 'run',
          gameSettings: settingsWithAdvanced,
          logToApp: { appName: app_name, runner: 'sideload' }
        })
        setRunningSetup(false)
        handleNextStepClick()
      } catch (error) {
        console.log('finished with error', error)
        setRunningSetup(false)
      }
    }
    return
  }

  async function detectAndContinue() {
    if (!preset) {
      return
    }

    setPresetPhase('detecting')
    const executable = await window.api.detectSideloadPresetExecutable(
      preset.id
    )

    if (executable) {
      setSelectedExe(executable)
      setPresetPhase('done')
      goToStep('finish')
      return
    }

    setPresetError('not-found')
    setPresetPhase('error')
  }

  async function startPresetInstall(silentOverride?: boolean) {
    if (!preset?.launcher) {
      return
    }

    const runId = ++presetRunId.current
    const isStale = () => presetRunId.current !== runId

    setPresetError('')
    setPresetDownloadProgress(0)
    setPresetPhase('downloading')

    try {
      await window.api.downloadSideloadPresetInstaller(preset.id)
      if (isStale()) {
        return
      }

      const gameSettings = await getGameSettings(app_name, 'sideload')
      if (!gameSettings) {
        throw new Error('Missing game settings')
      }
      // Windows installers run natively, so no Wine settings are needed there.
      if (platform !== 'win32') {
        await writeConfig({
          appName: app_name,
          config: getConfigOverride(withAdvancedSettings(gameSettings))
        })
      }
      if (isStale()) {
        return
      }

      setPresetPhase('running')
      const result = await window.api.runSideloadPresetInstaller(
        preset.id,
        silentOverride ?? installSilently
      )
      if (isStale()) {
        return
      }
      if (result.status === 'error') {
        throw new Error(result.error ?? 'installer-failed')
      }

      await detectAndContinue()
    } catch (error) {
      if (isStale()) {
        return
      }
      setPresetError(String(error))
      setPresetPhase('error')
    }
  }

  function handlePresetContinue() {
    presetRunId.current++
    void detectAndContinue()
  }

  function handlePresetRetry() {
    presetStarted.current = true
    void startPresetInstall()
  }

  function handlePresetRetryInteractive() {
    presetStarted.current = true
    setInstallSilently(false)
    void startPresetInstall(false)
  }

  function handleSelectExecutableManually() {
    goToStep('finish')
  }

  async function handleOpenWinetricks() {
    if (!app_name) {
      return
    }

    const gameSettings = await getGameSettings(app_name, 'sideload')
    if (!gameSettings) {
      return
    }

    await writeConfig({
      appName: app_name,
      config: getConfigOverride(withAdvancedSettings(gameSettings))
    })
    setWinetricksOpen(true)
  }

  function platformIcon() {
    const platformIcon = availablePlatforms.filter(
      (p) => p.name === appPlatform.replace('Mac', 'macOS')
    )[0]?.icon

    return (
      <FontAwesomeIcon
        className="InstallModal__platformIcon"
        icon={platformIcon}
      />
    )
  }

  const shouldShowRunExe = platform !== 'win32' && appPlatform === 'Windows'

  const stepInfo: Record<SupportedSteps, StepperStep> = {
    meta: {
      title: t('sideload.step.meta', 'Metadata'),
      description: t('sideload.step.meta-desc', 'Name and platform')
    },
    images: {
      title: t('sideload.step.images', 'Images'),
      description: t('sideload.step.images-desc', 'Cover and hero art')
    },
    compat: {
      title: t('sideload.step.compat', 'Compatibility'),
      description: t('sideload.step.compat-desc', 'Wine / Proton setup')
    },
    install: {
      title: t('sideload.step.install', 'Installation'),
      description: t('sideload.step.install-desc', 'Run the installer')
    },
    finish: {
      title: t('sideload.step.finish', 'Finish'),
      description: t('sideload.step.finish-desc', 'Executable and options')
    }
  }

  const presetStepInfo: Record<SupportedSteps, StepperStep> = {
    ...stepInfo,
    compat: {
      title:
        platform === 'win32'
          ? t('sideload.presets.step.install-options', 'Installation options')
          : t('sideload.presets.step.setup', 'Setup'),
      description:
        platform === 'win32'
          ? t(
              'sideload.presets.step.install-options-desc',
              'Silent installation'
            )
          : t('sideload.presets.step.setup-desc', 'Wine prefix and version')
    },
    install: {
      title: t('sideload.presets.step.install', 'Installation'),
      description: t(
        'sideload.presets.step.install-desc',
        'Download and run the installer'
      )
    },
    finish: {
      title: t('sideload.presets.step.options', 'Options'),
      description: t(
        'sideload.presets.step.options-desc',
        'Executable and launch options'
      )
    }
  }

  const flowSteps: SupportedSteps[] = useMemo(() => {
    if (preset) {
      const steps: SupportedSteps[] = []
      if (
        preset.kind === 'launcher' &&
        (platform !== 'win32' || preset.launcher?.installer.silentArgs)
      ) {
        steps.push('compat')
      }
      if (preset.kind === 'launcher') {
        steps.push('install')
      }
      steps.push('finish')
      return steps
    }

    const steps: SupportedSteps[] = ['meta', 'images']
    if (!editMode && shouldShowRunExe) {
      steps.push('compat', 'install')
    }
    steps.push('finish')
    return steps
  }, [preset, platform, editMode, shouldShowRunExe])

  useEffect(() => {
    if (!preset?.launcher) {
      return
    }
    if (flowSteps[activeStep] !== 'install') {
      return
    }
    if (presetStarted.current) {
      return
    }
    presetStarted.current = true
    void startPresetInstall()
    // startPresetInstall reads the current prefix/Wine state. It is guarded by
    // presetStarted, so re-running this effect does not restart the installer.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [activeStep, flowSteps, preset])

  const numberOfSteps = flowSteps.length
  const lastStepIndex = numberOfSteps - 1

  function goToStep(step: SupportedSteps) {
    const index = flowSteps.indexOf(step)
    if (index !== -1) {
      setActiveStep(index)
    }
  }

  function handlePreviousStepClick() {
    setActiveStep(Math.max(activeStep - 1, 0))
  }

  function handleNextStepClick() {
    if (activeStep === lastStepIndex) {
      void handleInstall()
      return
    }
    setActiveStep(Math.min(activeStep + 1, lastStepIndex))
  }

  function renderDialogContent(step: SupportedSteps) {
    switch (step) {
      case 'meta':
        return (
          <MetadataStep
            title={title}
            setTitle={setTitle}
            platformSelection={platformSelection}
          />
        )
      case 'images':
        return (
          <ImagesStep
            title={title}
            backdropClick={backdropClick}
            imageUrl={imageUrl}
            setImageUrl={setImageUrl}
            heroUrl={heroUrl}
            setHeroUrl={setHeroUrl}
            hasSgdbKey={hasSgdbKey}
          />
        )
      case 'compat':
        return (
          <div className="sideloadCompatForm">
            {preset?.requiresCrossover?.includes(
              platform as SideloadPresetPlatform
            ) && (
              <Alert variant="warning" className="sideloadPresetNote">
                {t(
                  'sideload.presets.macos-requires-crossover',
                  'macOS: this launcher needs the commercial CrossOver version. Free Wine builds can install it, but its window does not open.'
                )}
              </Alert>
            )}
            {preset?.launcher?.installer.silentArgs && (
              <ToggleSwitch
                htmlId="sideload-silent-install"
                title={t(
                  'sideload.presets.silent-install.title',
                  'Silent installation'
                )}
                description={t(
                  'sideload.presets.silent-install.description',
                  'Run the installer without showing its window. Turn this off if the silent install fails.'
                )}
                value={installSilently}
                handleChange={() => setInstallSilently(!installSilently)}
              />
            )}
            {platform !== 'win32' && (
              <>
                {wineSelector}
                <SideloadAdvanced
                  canRunWinetricks={Boolean(
                    wineVersion && winePrefix && winePrefix !== '...'
                  )}
                  onOpenWinetricks={() => void handleOpenWinetricks()}
                  environmentOptions={environmentOptions}
                  onEnvironmentOptionsChange={setEnvironmentOptions}
                  umuGameId={umuGameId}
                  onUmuGameIdChange={setUmuGameId}
                  showUmuOptions={
                    platform === 'linux' && wineVersion?.type === 'proton'
                  }
                />
              </>
            )}
          </div>
        )
      case 'install':
        if (preset?.launcher) {
          return (
            <PresetInstallStep
              appName={app_name}
              presetTitle={preset.title}
              phase={presetPhase}
              downloadProgress={presetDownloadProgress}
              error={presetError}
              onContinue={handlePresetContinue}
              onRetry={handlePresetRetry}
              onCheckAgain={() => void detectAndContinue()}
              onSelectManually={handleSelectExecutableManually}
              onCancel={handleCancelPreset}
              showInstallerNotice={Boolean(
                preset?.installerOpensApp?.includes(
                  platform as SideloadPresetPlatform
                )
              )}
              canRetryInteractive={Boolean(
                preset?.launcher?.installer.silentArgs
              )}
              onRetryInteractive={handlePresetRetryInteractive}
            />
          )
        }
        return (
          <InstallationStep
            appName={app_name}
            title={title}
            runningSetup={runningSetup}
            handleRunExe={handleRunExe}
            onSkip={handleNextStepClick}
            onFinish={handleInstall}
          />
        )
      case 'finish':
        return (
          <>
            {presetText?.note && (
              <Alert variant="info" className="sideloadPresetNote">
                {presetText.note}
              </Alert>
            )}
            {preset?.kind === 'launcher' && (
              <Alert variant="info" className="sideloadPresetNote">
                {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: preset.title }
                )}
              </Alert>
            )}
            {preset?.kind === 'launcher' && platform === 'win32' && (
              <Alert variant="warning" className="sideloadPresetNote">
                {t(
                  'sideload.presets.scan-platform-note',
                  'Scanning installed games is currently available on Linux and macOS only. On Windows, add games with the custom flow for now.'
                )}
              </Alert>
            )}
            <FinishStep
              appPlatform={appPlatform}
              gameUrl={gameUrl}
              setGameUrl={setGameUrl}
              customUserAgent={customUserAgent}
              setCustomUserAgent={setCustomUserAgent}
              launchFullScreen={launchFullScreen}
              setLaunchFullScreen={setLaunchFullScreen}
              winePrefix={winePrefix}
              wineVersion={wineVersion}
              selectedExe={selectedExe}
              setSelectedExe={setSelectedExe}
              fileFilters={fileFilters}
              launcherMode={preset?.kind === 'launcher'}
              presetTitle={preset?.title}
            />
          </>
        )
    }
  }

  const showNextButton = useMemo(() => {
    const step = flowSteps[activeStep]
    if (step === 'install') {
      // When the executable was already detected, allow going back to Options.
      return preset?.kind === 'launcher' && presetPhase === 'done'
    }
    return true
  }, [flowSteps, activeStep, preset, presetPhase])

  const noAppEntryPoint =
    (appPlatform !== 'Browser' && !selectedExe) ||
    (appPlatform === 'Browser' && !gameUrl)

  const lastStep = lastStepIndex === activeStep

  const presetBusy =
    preset?.kind === 'launcher' &&
    (presetPhase === 'downloading' ||
      presetPhase === 'running' ||
      presetPhase === 'detecting')

  useEffect(() => {
    onPresetBusyChange?.(presetBusy)
  }, [presetBusy, onPresetBusyChange])

  const cancelPresetRun = () => {
    presetRunId.current++
    presetStarted.current = false
    setPresetPhase('idle')
    setPresetError('')
    setPresetDownloadProgress(0)

    if (activeStep > 0) {
      setActiveStep(activeStep - 1)
    } else if (onBackToPresets) {
      onBackToPresets()
    } else {
      backdropClick()
    }
  }

  const handleCancelPreset = () => {
    if (!presetBusy) {
      cancelPresetRun()
      return
    }

    showDialogModal({
      title: t(
        'sideload.presets.closing.title',
        'Installation is still running'
      ),
      message: t(
        'sideload.presets.closing.message',
        'The installer is still running. Close the window anyway? The installer may keep running in the background.'
      ),
      type: 'MESSAGE',
      buttons: [
        {
          text: t('sideload.presets.closing.continue', 'Close anyway'),
          variant: 'primary',
          onClick: cancelPresetRun
        },
        {
          text: t('sideload.presets.closing.cancel', 'Keep installing')
        }
      ]
    })
  }

  const presetInstallStep =
    preset?.kind === 'launcher' && flowSteps[activeStep] === 'install'

  const canReturnToPresets = Boolean(
    preset && onBackToPresets && activeStep === 0
  )

  return (
    <>
      <ModalContent className="sideloadDialog">
        {flowSteps.length > 1 && (
          <Stepper
            className="sideloadStepper"
            activeStep={activeStep}
            steps={flowSteps.map((step) =>
              preset ? presetStepInfo[step] : stepInfo[step]
            )}
          />
        )}
        <div className="stepContentRenderer">
          {renderDialogContent(flowSteps[activeStep])}
        </div>
      </ModalContent>
      <ModalFooter className="sideload">
        <div className="sideloadFooterMetadata">
          {title}
          {platformIcon()}
        </div>
        <div className="sideloadFooterButtons">
          <Button
            variant="ghost"
            onClick={() => {
              if (presetInstallStep) {
                handleCancelPreset()
                return
              }
              if (canReturnToPresets && onBackToPresets) {
                onBackToPresets()
                return
              }
              handlePreviousStepClick()
            }}
            disabled={
              addingApp ||
              runningSetup ||
              (activeStep === 0 && !canReturnToPresets)
            }
          >
            {t('button.back', 'Back')}
          </Button>
          {showNextButton && (
            <Button
              variant="primary"
              onClick={handleNextStepClick}
              disabled={
                (lastStep && (noAppEntryPoint || !wineSelectionValid)) ||
                addingApp ||
                runningSetup ||
                presetBusy
              }
            >
              {lastStep
                ? t('button.finish', 'Finish')
                : t('button.next', 'Next')}
            </Button>
          )}
        </div>
      </ModalFooter>
      {winetricksOpen && (
        <Winetricks
          appName={app_name}
          runner="sideload"
          onClose={() => setWinetricksOpen(false)}
        />
      )}
    </>
  )
}