Skip to content

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

1.9 KB
Raw Blame
import React, { useContext } from 'react'
import { ToggleSwitch } from 'frontend/components/UI'
import useSetting from 'frontend/hooks/useSetting'
import { useTranslation } from 'react-i18next'
import { defaultWineVersion } from '../util'
import SettingsContext from '../SettingsContext'

const AutoDXVKNVAPI = () => {
  const { t } = useTranslation()
  const [autoInstallDxvk] = useSetting('autoInstallDxvk', false)
  const [autoInstallDXVKNVAPI, setAutoInstallDXVKNVAPI] = useSetting(
    'autoInstallDxvkNvapi',
    false
  )
  const { appName } = useContext(SettingsContext)
  const [wineVersion] = useSetting('wineVersion', defaultWineVersion)
  const [installingDxvkNvapi, setInstallingDxvkNvapi] = React.useState(false)

  if (wineVersion.type !== 'wine') {
    return <></>
  }

  const handleAutoInstallDxvkNvapi = async () => {
    let res = true

    setInstallingDxvkNvapi(true)
    const action = autoInstallDXVKNVAPI ? 'restore' : 'backup'
    res = await window.api.toggleDXVKNVAPI({
      appName,
      action
    })

    setInstallingDxvkNvapi(false)
    if (res) {
      setAutoInstallDXVKNVAPI(!autoInstallDXVKNVAPI)
    }
  }

  return (
    <ToggleSwitch
      info={t(
        'help.dxvknvapi',
        'DXVK-NVAPI is an implementation of NVAPI built on top of DXVK and the linux native NVAPI, it allows for the usage of DLSS on Nvidia GPUs.'
      )}
      description={t(
        'setting.autodxvknvapi-description',
        'Expose NVIDIA features such as DLSS to games running through DXVK'
      )}
      htmlId="autodxvknvapi"
      value={autoInstallDXVKNVAPI}
      handleChange={handleAutoInstallDxvkNvapi}
      title={
        installingDxvkNvapi
          ? t('please-wait', 'Please wait...')
          : t(
              'setting.autodxvknvapi',
              'Auto install/update DXVK-NVAPI on prefix'
            )
      }
      fading={installingDxvkNvapi}
      disabled={!autoInstallDxvk || installingDxvkNvapi}
    />
  )
}

export default AutoDXVKNVAPI