Skip to content

Commit

Permalink
[FIX] Games Auto Update (#766)
Browse files Browse the repository at this point in the history
* [FIX] Games Auto Update

* add null checks

* chore: await 3 seconds before updaring the queue

---------

Co-authored-by: Flavio F Lima <[email protected]>
Co-authored-by: Brett <[email protected]>
  • Loading branch information
3 people committed Mar 15, 2024
1 parent 4d53936 commit 786e579
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ ipcMain.handle('checkGameUpdates', async (): Promise<string[]> => {
for (const runner in libraryManagerMap) {
let gamesToUpdate = await libraryManagerMap[runner].listUpdateableGames()
if (autoUpdateGames) {
gamesToUpdate = autoUpdate(runner as Runner, gamesToUpdate)
gamesToUpdate = await autoUpdate(runner as Runner, gamesToUpdate)
}
oldGames = [...oldGames, ...gamesToUpdate]
}
Expand Down
14 changes: 8 additions & 6 deletions src/backend/storeManagers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { DMQueueElement, GameInfo, Runner } from 'common/types'
import { ipcMain } from 'electron'
import { sendFrontendMessage } from 'backend/main_window'
import { loadEpicHyperPlayGameInfoMap } from './hyperplay/utils'
import { isGameAvailable } from 'backend/api/helpers'

import { notify } from '../dialog/dialog'
import i18next from 'i18next'
import { wait } from 'backend/utils'

const MAX_GAMES_UPDATE_NOTIFICATIONS = 3

Expand Down Expand Up @@ -61,30 +62,31 @@ function getDMElement(gameInfo: GameInfo, appName: string) {
return dmQueueElement
}

export function autoUpdate(runner: Runner, gamesToUpdate: string[]) {
export async function autoUpdate(runner: Runner, gamesToUpdate: string[]) {
const logPrefix = RunnerToLogPrefixMap[runner]
gamesToUpdate.forEach(async (appName) => {
for (const appName of gamesToUpdate) {
const { ignoreGameUpdates } = await gameManagerMap[runner].getSettings(
appName
)
const gameInfo = gameManagerMap[runner].getGameInfo(appName)
const gameAvailable = await isGameAvailable({ appName, runner })
const gameAvailable = gameManagerMap[runner].isGameAvailable(appName)

if (!gameAvailable) {
logInfo(`Skipping auto-update for ${gameInfo.title}`, logPrefix)
return
continue
}

if (!ignoreGameUpdates) {
logInfo(`Auto-Updating ${gameInfo.title}`, logPrefix)
const dmQueueElement: DMQueueElement = getDMElement(gameInfo, appName)
await wait(3000)
addToQueue(dmQueueElement)
// remove from the array to avoid downloading the same game twice
gamesToUpdate = gamesToUpdate.filter((game) => game !== appName)
} else {
logInfo(`Skipping auto-update for ${gameInfo.title}`, logPrefix)
}
})
}
return gamesToUpdate
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/wiki_game_info/pcgamingwiki/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function getPageID(title: string, id?: string): Promise<string | null> {
`https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageID%3DpageID%2C&where=Infobox_game.GOGcom_ID%20HOLDS%20${id}&format=json`
)

const number = data.cargoquery[0]?.title?.pageID
const number = data?.cargoquery[0]?.title?.pageID

if (number) {
return number
Expand All @@ -72,7 +72,7 @@ async function getPageID(title: string, id?: string): Promise<string | null> {
)}"&format=json`
)

return data.cargoquery[0]?.title?.pageID
return data?.cargoquery[0]?.title?.pageID
}

async function getWikiText(id: string): Promise<string | null> {
Expand Down

0 comments on commit 786e579

Please sign in to comment.