Skip to content

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

3.9 KB
Raw Blame
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
  GameInfo,
  InstallPlatform,
  Runner,
  WineInstallation
} from 'common/types'
import Anticheat from 'frontend/components/UI/Anticheat'
import {
  ModalFooter,
  ModalHeader,
  ModalContent
} from 'frontend/components/UI/Modal'
import Button from 'frontend/components/UI/Button'
import { writeConfig } from 'frontend/helpers'
import { install } from 'frontend/helpers/library'
import { hasAnticheatInfo } from 'frontend/hooks/hasAnticheatInfo'
import ContextProvider from 'frontend/state/ContextProvider'
import { InstallProgress } from 'frontend/types'
import React, { useCallback, useContext } from 'react'
import { useTranslation } from 'react-i18next'
import AllowedIcon from 'frontend/assets/rounded_checkmark_icon.svg?react'
import { AvailablePlatforms } from '..'
import './index.css'

interface Props {
  backdropClick: () => void
  appName: string
  runner: Runner
  platformToInstall: InstallPlatform
  availablePlatforms: AvailablePlatforms
  winePrefix: string
  crossoverBottle: string
  wineVersion: WineInstallation | undefined
  children: React.ReactNode
  gameInfo: GameInfo
}

export default function ThirdPartyDialog({
  appName,
  runner,
  backdropClick,
  gameInfo,
  availablePlatforms,
  wineVersion,
  children,
  crossoverBottle,
  winePrefix,
  platformToInstall
}: Props) {
  const { t } = useTranslation('gamepage')
  const { platform } = useContext(ContextProvider)
  const isWin = platform === 'win32'
  const progress = {} as InstallProgress

  const anticheatInfo = hasAnticheatInfo(gameInfo)

  const handleInstall = useCallback(async () => {
    // Write Default game config with prefix on linux
    if (!isWin) {
      const gameSettings = await window.api.requestGameSettings(appName)

      if (wineVersion) {
        writeConfig({
          appName,
          config: {
            ...gameSettings,
            winePrefix,
            wineVersion,
            wineCrossoverBottle: crossoverBottle
          }
        })
      }
    }

    backdropClick()

    return install({
      gameInfo,
      previousProgress: progress,
      progress,
      installPath: 'thirdParty',
      isInstalling: false,
      t,
      platformToInstall,
      showDialogModal: () => backdropClick()
    })
  }, [appName, t, winePrefix, wineVersion, crossoverBottle, platformToInstall])

  return (
    <>
      <ModalHeader>
        {gameInfo.overrides?.title || gameInfo.title}
        {availablePlatforms.map((p) => (
          <FontAwesomeIcon
            className="InstallModal__platformIcon"
            icon={p.icon}
            key={p.value}
          />
        ))}
      </ModalHeader>
      <ModalContent>
        <div className="thirdPartyNotice">
          <div className="noticeIcon">
            <AllowedIcon />
          </div>
          <div className="noticeInfo">
            <h4>
              {t(
                'third-party-managed.header',
                'This game is managed by a third-party application'
              )}
            </h4>
            <p>
              {t(
                'third-party-managed.notice1',
                'This game is managed by a third-party application: "{{application_name}}"',
                {
                  application_name: gameInfo.isEAManaged
                    ? 'EA app'
                    : gameInfo.thirdPartyManagedApp
                }
              )}
            </p>
            <p>
              {t(
                'third-party-managed.notice2',
                'After clicking Install, Heroic will run the application in order to complete the installation process'
              )}
            </p>
          </div>
        </div>
        <Anticheat anticheatInfo={anticheatInfo} />
        {children}
      </ModalContent>
      <ModalFooter>
        <Button onClick={handleInstall} disabled={runner !== 'legendary'}>
          {t('button.install')}
        </Button>
      </ModalFooter>
    </>
  )
}