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 { useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { LoaderCircle } from 'lucide-react'
import { Modal, ModalContent, ModalFooter, ModalHeader } from '../Modal'
import Button from '../Button'
import Icon from '../Icon'
import useGlobalState from 'frontend/state/GlobalStateV2'
export default function LogUploadDialog() {
const { t } = useTranslation()
const { uploadLogFileProps, setUploadLogFileProps } = useGlobalState.keys(
'uploadLogFileProps',
'setUploadLogFileProps'
)
const [confirmed, setConfirmed] = useState(false)
const [uploading, setUploading] = useState(false)
const [error, setError] = useState(false)
const [uploadUrl, setUploadUrl] = useState<string | null>(null)
const onClose = useCallback(() => {
setConfirmed(false)
setUploading(false)
setUploadLogFileProps(false)
}, [setConfirmed, setUploading, setUploadLogFileProps])
const doUpload = useCallback(async () => {
if (!uploadLogFileProps) return
setConfirmed(true)
setUploading(true)
const result = await window.api.uploadLogFile(
uploadLogFileProps.name,
uploadLogFileProps.logFileArgs
)
setUploading(false)
if (!result) {
setError(true)
return
}
const [url] = result
await navigator.clipboard.writeText(url)
setUploadUrl(url)
}, [uploadLogFileProps])
const [dialogTitle, dialogContent, dialogFooter] = useMemo(() => {
if (!uploadLogFileProps) return ['', '', '']
if (!confirmed)
return [
t('setting.log.upload.confirm.title', 'Upload log file?'),
t(
'setting.log.upload.confirm.content',
'Do you really want to upload "{{name}}"?',
{ name: uploadLogFileProps.name }
),
<>
<Button onClick={doUpload}>{t('box.yes')}</Button>
<Button variant="secondary" onClick={onClose}>
{t('box.no')}
</Button>
</>
]
if (uploading)
return [
t('setting.log.upload.uploading.title', 'Uploading'),
<>
<Icon glyph={LoaderCircle} size="xl" className="lucide-spin" />
<br />
{t('setting.log.upload.uploading.content', 'Uploading log file...')}
</>,
<></>
]
if (error)
return [
t('setting.log.upload.error.title', 'Upload failed'),
<>
{t(
'setting.log.upload.error.content',
"Failed to upload log file. Check Heroic's general log for details"
)}
<br />
<br />
{t(
'setting.log.upload.error.manual_upload',
'Click the "SHOW LOG FILE IN FOLDER" button and upload the "launch.log" file manually to Discord or any online file sharing service.'
)}
</>,
<>
<Button variant="secondary" onClick={onClose}>
{t('box.ok')}
</Button>
</>
]
return [
t('setting.log.upload.done.title', 'Upload complete'),
t(
'setting.log.upload.done.content',
'Uploaded to {{url}} (URL copied to your clipboard)',
{
url: uploadUrl
}
),
<>
<Button onClick={onClose}>{t('box.ok')}</Button>
</>
]
}, [uploadLogFileProps, confirmed, uploading, error, uploadUrl])
if (!uploadLogFileProps) return <></>
return (
<Modal
onClose={onClose}
size="sm"
tone={error ? 'error' : 'default'}
className="log-upload-result"
>
<ModalHeader>{dialogTitle}</ModalHeader>
<ModalContent>{dialogContent}</ModalContent>
<ModalFooter>{dialogFooter}</ModalFooter>
</Modal>
)
}