Skip to content

Commit 786e579

Browse files
[FIX] Games Auto Update (#766)
* [FIX] Games Auto Update * add null checks * chore: await 3 seconds before updaring the queue --------- Co-authored-by: Flavio F Lima <flavioislima@users.noreply.github.com> Co-authored-by: Brett <27568879+BrettCleary@users.noreply.github.com>
1 parent 4d53936 commit 786e579

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/backend/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ ipcMain.handle('checkGameUpdates', async (): Promise<string[]> => {
798798
for (const runner in libraryManagerMap) {
799799
let gamesToUpdate = await libraryManagerMap[runner].listUpdateableGames()
800800
if (autoUpdateGames) {
801-
gamesToUpdate = autoUpdate(runner as Runner, gamesToUpdate)
801+
gamesToUpdate = await autoUpdate(runner as Runner, gamesToUpdate)
802802
}
803803
oldGames = [...oldGames, ...gamesToUpdate]
804804
}

src/backend/storeManagers/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import { DMQueueElement, GameInfo, Runner } from 'common/types'
1818
import { ipcMain } from 'electron'
1919
import { sendFrontendMessage } from 'backend/main_window'
2020
import { loadEpicHyperPlayGameInfoMap } from './hyperplay/utils'
21-
import { isGameAvailable } from 'backend/api/helpers'
21+
2222
import { notify } from '../dialog/dialog'
2323
import i18next from 'i18next'
24+
import { wait } from 'backend/utils'
2425

2526
const MAX_GAMES_UPDATE_NOTIFICATIONS = 3
2627

@@ -61,30 +62,31 @@ function getDMElement(gameInfo: GameInfo, appName: string) {
6162
return dmQueueElement
6263
}
6364

64-
export function autoUpdate(runner: Runner, gamesToUpdate: string[]) {
65+
export async function autoUpdate(runner: Runner, gamesToUpdate: string[]) {
6566
const logPrefix = RunnerToLogPrefixMap[runner]
66-
gamesToUpdate.forEach(async (appName) => {
67+
for (const appName of gamesToUpdate) {
6768
const { ignoreGameUpdates } = await gameManagerMap[runner].getSettings(
6869
appName
6970
)
7071
const gameInfo = gameManagerMap[runner].getGameInfo(appName)
71-
const gameAvailable = await isGameAvailable({ appName, runner })
72+
const gameAvailable = gameManagerMap[runner].isGameAvailable(appName)
7273

7374
if (!gameAvailable) {
7475
logInfo(`Skipping auto-update for ${gameInfo.title}`, logPrefix)
75-
return
76+
continue
7677
}
7778

7879
if (!ignoreGameUpdates) {
7980
logInfo(`Auto-Updating ${gameInfo.title}`, logPrefix)
8081
const dmQueueElement: DMQueueElement = getDMElement(gameInfo, appName)
82+
await wait(3000)
8183
addToQueue(dmQueueElement)
8284
// remove from the array to avoid downloading the same game twice
8385
gamesToUpdate = gamesToUpdate.filter((game) => game !== appName)
8486
} else {
8587
logInfo(`Skipping auto-update for ${gameInfo.title}`, logPrefix)
8688
}
87-
})
89+
}
8890
return gamesToUpdate
8991
}
9092

src/backend/wiki_game_info/pcgamingwiki/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function getPageID(title: string, id?: string): Promise<string | null> {
5858
`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`
5959
)
6060

61-
const number = data.cargoquery[0]?.title?.pageID
61+
const number = data?.cargoquery[0]?.title?.pageID
6262

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

75-
return data.cargoquery[0]?.title?.pageID
75+
return data?.cargoquery[0]?.title?.pageID
7676
}
7777

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

0 commit comments

Comments
 (0)