From 9db2ab1f455b5c92fe3579d8ff9148af9a821eec Mon Sep 17 00:00:00 2001 From: Flavio F Lima <26871415+flavioislima@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:53:38 +0000 Subject: [PATCH] fix: pr comments --- src/backend/downloadmanager/downloadqueue.ts | 83 +++++++++++++++----- src/backend/storeManagers/hyperplay/games.ts | 2 +- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/backend/downloadmanager/downloadqueue.ts b/src/backend/downloadmanager/downloadqueue.ts index 513104347..662c71d08 100644 --- a/src/backend/downloadmanager/downloadqueue.ts +++ b/src/backend/downloadmanager/downloadqueue.ts @@ -144,23 +144,59 @@ async function addToQueue(element: DMQueueElement) { element.channel = element.params.channelName ?? 'main' if (!element.params.size) { - const installSize = installInfo?.manifest?.download_size - ? getFileSize(installInfo?.manifest?.download_size) - : '?? MB' - - const updateSize = - // @ts-expect-error - confusion because of the platform - element.params.gameInfo.channels[element.channel!].release_meta - .platforms[element.params.platformToInstall].downloadSize - ? getFileSize( - // @ts-expect-error - confusion because of the platform - element.params.gameInfo.channels[element.channel!].release_meta - .platforms[element.params.platformToInstall].downloadSize - ) - : '?? MB' - - element.params.size = - element.type === 'install' ? installSize : updateSize + let size = '?? MB' + if (element.type === 'install') { + const installSize = installInfo?.manifest?.download_size + if (installSize) { + size = getFileSize(installSize) + } + } else { + const { + channelName, + platformToInstall, + gameInfo: { channels } + } = element.params + + const updateSize = + // @ts-expect-error - confusion because of the platform type + channels[channelName ?? 'main'].release_meta.platforms[ + platformToInstall + ]?.downloadSize + + if (updateSize) { + size = getFileSize(updateSize) + } + } + + element.params.size = size + } + + if (!element.params.size) { + let size = '?? MB' + if (element.type === 'install') { + const installSize = installInfo?.manifest?.download_size + if (installSize) { + size = getFileSize(installSize) + } + } else { + const { + channelName, + platformToInstall, + gameInfo: { channels } + } = element.params + + const updateSize = + // @ts-expect-error - confusion because of the platform type + channels[channelName ?? 'main'].release_meta.platforms[ + platformToInstall + ].downloadSize + + if (updateSize) { + size = getFileSize(updateSize) + } + } + + element.params.size = size } elements.push(element) @@ -373,9 +409,7 @@ async function updateQueueElementParam( ) if (index !== -1) { queue[index][prop] = value - if (currentElement) { - currentElement[prop] = value - } + updateCurrentElementParam(prop, value) downloadManager.set('queue', queue) sendFrontendMessage('changedDMQueueInformation', queue, queueState) } else { @@ -383,6 +417,15 @@ async function updateQueueElementParam( } } +function updateCurrentElementParam( + prop: T, + value: DMQueueElement[T] +) { + if (currentElement) { + currentElement[prop] = value + } +} + export { initQueue, addToQueue, diff --git a/src/backend/storeManagers/hyperplay/games.ts b/src/backend/storeManagers/hyperplay/games.ts index ee3c7be1c..27bba448f 100644 --- a/src/backend/storeManagers/hyperplay/games.ts +++ b/src/backend/storeManagers/hyperplay/games.ts @@ -1925,7 +1925,7 @@ async function getManifest( } } ) - return '' + throw new Error(`Error in getManifest for ${appName}: ${error}`) } }