-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Add DLCs manager for Epic Games (#2734)
* chore: update types * fix: types * feat: add DLC list component * feat: update uninstall modal * fix_ possibly undefined * feat: add install DLCs method * feat: add dlc size and cancel button * fix: lint * i18n: updated keys * UI: fixes and no DLC found message * i18n: keys * feat: add DLCs selector on install dialog * feat: add Dlcs to the download queue after main game * i18n: updated keys * fix: remove dlcs from the queue if main game was removed * fix: pr comments * Update src/backend/downloadmanager/downloadqueue.ts Co-authored-by: Mathis Dröge <mathis.droege@ewe.net> * fix: hide DLCs submenu if game is not installed * fix: do not pass with-dlcs flag to legendary anymore * ui: use svg icons to keep consistency * i18n: update keys * fix: don't navigate to dlc gamepage from queue --------- Co-authored-by: Mathis Dröge <mathis.droege@ewe.net>
- Loading branch information
1 parent
1bb0de2
commit 0ae766a
Showing
23 changed files
with
493 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.dlcItem { | ||
display: grid; | ||
grid-template-columns: 3fr 1fr 1fr; | ||
grid-template-rows: auto; | ||
grid-gap: var(--space-md-fixed); | ||
grid-template-areas: 'title size action'; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 1rem 0; | ||
border-bottom: 1px solid #ccc; | ||
|
||
&:last-child { | ||
border-bottom: none; | ||
} | ||
.title { | ||
grid-area: title; | ||
font-weight: 400; | ||
} | ||
.size { | ||
grid-area: size; | ||
font-weight: 400; | ||
text-align: center; | ||
} | ||
.action { | ||
grid-area: action; | ||
font-weight: 400; | ||
text-align: center; | ||
cursor: pointer; | ||
color: var(--primary); | ||
transition: color 0.2s ease-in-out; | ||
&:hover { | ||
color: var(--secondary); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import React, { useContext, useEffect, useState } from 'react' | ||
import { DLCInfo } from 'common/types/legendary' | ||
import './index.scss' | ||
import { useTranslation } from 'react-i18next' | ||
import { getGameInfo, getInstallInfo, install, size } from 'frontend/helpers' | ||
import { GameInfo, Runner } from 'common/types' | ||
import UninstallModal from 'frontend/components/UI/UninstallModal' | ||
import { faSpinner } from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import ContextProvider from 'frontend/state/ContextProvider' | ||
import { hasProgress } from 'frontend/hooks/hasProgress' | ||
import { ReactComponent as DownIcon } from 'frontend/assets/down-icon.svg' | ||
import { ReactComponent as StopIcon } from 'frontend/assets/stop-icon.svg' | ||
import { ReactComponent as StopIconAlt } from 'frontend/assets/stop-icon-alt.svg' | ||
import SvgButton from '../../SvgButton' | ||
|
||
type Props = { | ||
dlc: DLCInfo | ||
runner: Runner | ||
mainAppInfo: GameInfo | ||
onClose: () => void | ||
} | ||
|
||
const DLC = ({ dlc, runner, mainAppInfo, onClose }: Props) => { | ||
const { title, app_name } = dlc | ||
const { libraryStatus, showDialogModal } = useContext(ContextProvider) | ||
const { t } = useTranslation('gamepage') | ||
const [showUninstallModal, setShowUninstallModal] = useState(false) | ||
const [dlcInfo, setDlcInfo] = useState<GameInfo | null>(null) | ||
const [dlcSize, setDlcSize] = useState<number>(0) | ||
const [refreshing, setRefreshing] = useState(true) | ||
const [progress] = hasProgress(app_name) | ||
|
||
const isInstalled = dlcInfo?.is_installed | ||
|
||
useEffect(() => { | ||
const checkInstalled = async () => { | ||
const info = await getGameInfo(app_name, runner) | ||
if (!info) { | ||
return | ||
} | ||
setDlcInfo(info) | ||
} | ||
checkInstalled() | ||
}, [dlc, runner]) | ||
|
||
useEffect(() => { | ||
setRefreshing(true) | ||
const getDlcSize = async () => { | ||
if (!mainAppInfo.install.platform) { | ||
return | ||
} | ||
const info = await getInstallInfo( | ||
app_name, | ||
runner, | ||
mainAppInfo.install.platform | ||
) | ||
if (!info) { | ||
return | ||
} | ||
setDlcSize(info.manifest.download_size) | ||
setRefreshing(false) | ||
} | ||
getDlcSize() | ||
}, [dlc, runner]) | ||
|
||
const currentApp = libraryStatus.find((app) => app.appName === app_name) | ||
const isInstalling = currentApp?.status === 'installing' | ||
const showInstallButton = !isInstalling && !refreshing | ||
|
||
function mainAction() { | ||
if (isInstalled) { | ||
setShowUninstallModal(true) | ||
} else { | ||
const { | ||
install: { platform, install_path } | ||
} = mainAppInfo | ||
|
||
if (!dlcInfo || !platform || !install_path) { | ||
return | ||
} | ||
onClose() | ||
install({ | ||
isInstalling, | ||
previousProgress: null, | ||
progress, | ||
showDialogModal, | ||
t, | ||
installPath: install_path, | ||
gameInfo: dlcInfo, | ||
platformToInstall: platform | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{showUninstallModal && ( | ||
<UninstallModal | ||
appName={app_name} | ||
runner={runner} | ||
onClose={() => setShowUninstallModal(false)} | ||
isDlc | ||
/> | ||
)} | ||
<div className="dlcItem"> | ||
<span className="title">{title}</span> | ||
{refreshing ? '...' : <span className="size">{size(dlcSize)}</span>} | ||
{showInstallButton && ( | ||
<SvgButton | ||
className="action" | ||
onClick={() => mainAction()} | ||
title={`${ | ||
isInstalled | ||
? t('button.uninstall', 'Uninstall') | ||
: t('button.install', 'Install') | ||
} (${title})`} | ||
> | ||
{isInstalled ? <StopIcon /> : <DownIcon />} | ||
</SvgButton> | ||
)} | ||
{isInstalling && ( | ||
<SvgButton | ||
className="action" | ||
onClick={() => mainAction()} | ||
title={`${t('button.cancel', 'Cancel')} (${title})`} | ||
> | ||
<StopIconAlt /> | ||
</SvgButton> | ||
)} | ||
{refreshing && ( | ||
<span className="action"> | ||
<FontAwesomeIcon className={'fa-spin-pulse'} icon={faSpinner} /> | ||
</span> | ||
)} | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default React.memo(DLC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.dlcHeader { | ||
display: grid; | ||
grid-template-columns: 3fr 1fr 1fr; | ||
grid-template-rows: auto; | ||
grid-gap: 10px; | ||
font-weight: 700; | ||
color: var(--text-default); | ||
|
||
.title { | ||
grid-column: 1 / 2; | ||
} | ||
|
||
.size { | ||
grid-column: 2 / 3; | ||
text-align: center; | ||
} | ||
|
||
.actions { | ||
grid-column: 3 / 4; | ||
text-align: center; | ||
} | ||
} |
Oops, something went wrong.