Skip to content

Commit 37cdf7e

Browse files
authored
[Tech/UX] Allow for separate library refreshes (Heroic-Games-Launcher#1356)
* allow for separate library refreshes * Change library parameter to Runner type; use switch statements
1 parent 713faaf commit 37cdf7e

File tree

6 files changed

+52
-23
lines changed

6 files changed

+52
-23
lines changed

electron/main.ts

+27-9
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,18 @@ ipcMain.handle(
590590

591591
/// IPC handlers begin here.
592592

593-
ipcMain.handle('checkGameUpdates', async () => {
594-
const legendaryUpdates = await LegendaryLibrary.get().listUpdateableGames()
595-
const gogUpdates = await GOGLibrary.get().listUpdateableGames()
596-
return [...legendaryUpdates, ...gogUpdates]
593+
ipcMain.handle('checkGameUpdates', async (event, library?: Runner) => {
594+
switch (library) {
595+
case 'legendary':
596+
return LegendaryLibrary.get().listUpdateableGames()
597+
case 'gog':
598+
return GOGLibrary.get().listUpdateableGames()
599+
default:
600+
return [
601+
...(await LegendaryLibrary.get().listUpdateableGames()),
602+
...(await GOGLibrary.get().listUpdateableGames())
603+
]
604+
}
597605
})
598606

599607
ipcMain.handle('getEpicGamesStatus', async () => isEpicServiceOffline())
@@ -747,11 +755,21 @@ if (existsSync(installed)) {
747755
})
748756
}
749757

750-
ipcMain.handle('refreshLibrary', async (e, fullRefresh) => {
751-
await Promise.allSettled([
752-
GOGLibrary.get().sync(),
753-
LegendaryLibrary.get().getGames('info', fullRefresh)
754-
])
758+
ipcMain.handle('refreshLibrary', async (e, fullRefresh, library?: Runner) => {
759+
switch (library) {
760+
case 'legendary':
761+
await LegendaryLibrary.get().getGames('info', fullRefresh)
762+
break
763+
case 'gog':
764+
await GOGLibrary.get().sync()
765+
break
766+
default:
767+
await Promise.allSettled([
768+
LegendaryLibrary.get().getGames('info', fullRefresh),
769+
GOGLibrary.get().sync()
770+
])
771+
break
772+
}
755773
})
756774

757775
ipcMain.on('logError', (e, err) => logError(`${err}`, LogPrefix.Frontend))

src/components/UI/ActionIcons/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import { useTranslation } from 'react-i18next'
1515
import ContextProvider from 'src/state/ContextProvider'
1616
import FormControl from '../FormControl'
1717
import './index.css'
18+
import { Runner } from 'src/types'
1819

1920
interface Props {
2021
sortDescending: boolean
2122
sortInstalled: boolean
2223
toggleSortDescending: () => void
2324
toggleSortinstalled: () => void
25+
library: Runner
2426
}
2527

2628
export default function ActionIcons({
29+
library,
2730
sortDescending,
2831
toggleSortDescending,
2932
sortInstalled,
@@ -85,7 +88,8 @@ export default function ActionIcons({
8588
refreshLibrary({
8689
checkForUpdates: true,
8790
fullRefresh: true,
88-
runInBackground: false
91+
runInBackground: false,
92+
library
8993
})
9094
}
9195
>

src/screens/Game/GameSubMenu/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default function GamesSubmenu({
7979
})
8080
if (path) {
8181
await renderer.invoke('changeInstallPath', [appName, path, runner])
82-
await refresh()
82+
await refresh(runner)
8383
}
8484
return
8585
}

src/screens/Library/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default function Library(): JSX.Element {
105105
sortDescending={sortDescending}
106106
toggleSortDescending={() => handleSortDescending()}
107107
sortInstalled={sortInstalled}
108+
library={category === 'epic' ? 'legendary' : 'gog'}
108109
toggleSortinstalled={() => handleSortInstalled()}
109110
/>
110111
</div>

src/state/GlobalState.tsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
InstalledInfo,
99
LibraryTopSectionOptions,
1010
RefreshOptions,
11+
Runner,
1112
WineVersionInfo
1213
} from 'src/types'
1314
import { TFunction, withTranslation } from 'react-i18next'
@@ -232,12 +233,13 @@ export class GlobalState extends PureComponent<Props> {
232233
this.setState({ libraryTopSection: value })
233234
}
234235

235-
handleSuccessfulLogin = (runner: 'epic' | 'gog') => {
236+
handleSuccessfulLogin = (runner: Runner) => {
236237
this.handleFilter('all')
237238
this.handleCategory(runner)
238239
this.refreshLibrary({
239240
fullRefresh: true,
240-
runInBackground: false
241+
runInBackground: false,
242+
library: runner
241243
})
242244
}
243245

@@ -253,7 +255,7 @@ export class GlobalState extends PureComponent<Props> {
253255
}
254256
})
255257

256-
this.handleSuccessfulLogin('epic')
258+
this.handleSuccessfulLogin('legendery' as Runner)
257259
}
258260

259261
return response.status
@@ -289,7 +291,7 @@ export class GlobalState extends PureComponent<Props> {
289291
window.location.reload()
290292
}
291293

292-
refresh = async (checkUpdates?: boolean): Promise<void> => {
294+
refresh = async (library?: Runner, checkUpdates?: boolean): Promise<void> => {
293295
console.log('refreshing')
294296

295297
let updates = this.state.gameUpdates
@@ -309,7 +311,7 @@ export class GlobalState extends PureComponent<Props> {
309311

310312
try {
311313
updates = checkUpdates
312-
? await ipcRenderer.invoke('checkGameUpdates')
314+
? await ipcRenderer.invoke('checkGameUpdates', library)
313315
: this.state.gameUpdates
314316
} catch (error) {
315317
ipcRenderer.send('logError', error)
@@ -338,7 +340,8 @@ export class GlobalState extends PureComponent<Props> {
338340
refreshLibrary = async ({
339341
checkForUpdates,
340342
fullRefresh,
341-
runInBackground = true
343+
runInBackground = true,
344+
library = undefined
342345
}: RefreshOptions): Promise<void> => {
343346
if (this.state.refreshing) return
344347

@@ -348,11 +351,11 @@ export class GlobalState extends PureComponent<Props> {
348351
})
349352
ipcRenderer.send('logInfo', 'Refreshing Library')
350353
try {
351-
await ipcRenderer.invoke('refreshLibrary', fullRefresh)
354+
await ipcRenderer.invoke('refreshLibrary', fullRefresh, library)
352355
} catch (error) {
353356
ipcRenderer.send('logError', error)
354357
}
355-
this.refresh(checkForUpdates)
358+
this.refresh(library, checkForUpdates)
356359
}
357360

358361
refreshWineVersionInfo = async (fetch: boolean): Promise<void> => {
@@ -407,7 +410,8 @@ export class GlobalState extends PureComponent<Props> {
407410
appName,
408411
status,
409412
folder,
410-
progress
413+
progress,
414+
runner
411415
}: GameStatus) => {
412416
const { libraryStatus, gameUpdates } = this.state
413417
const currentApp = libraryStatus.filter(
@@ -440,7 +444,8 @@ export class GlobalState extends PureComponent<Props> {
440444
// This avoids calling legendary again before the previous process is killed when canceling
441445
this.refreshLibrary({
442446
checkForUpdates: true,
443-
runInBackground: true
447+
runInBackground: true,
448+
library: runner
444449
})
445450

446451
storage.setItem(
@@ -454,7 +459,7 @@ export class GlobalState extends PureComponent<Props> {
454459
})
455460
}
456461

457-
this.refreshLibrary({ runInBackground: true })
462+
this.refreshLibrary({ runInBackground: true, library: runner })
458463
this.setState({ libraryStatus: newLibraryStatus })
459464
}
460465
}

src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface ContextType {
7070
libraryTopSection: string
7171
handleLibraryTopSection: (value: LibraryTopSectionOptions) => void
7272
platform: NodeJS.Platform | string
73-
refresh: (checkUpdates?: boolean) => Promise<void>
73+
refresh: (library: Runner, checkUpdates?: boolean) => Promise<void>
7474
refreshLibrary: (options: RefreshOptions) => Promise<void>
7575
refreshWineVersionInfo: (fetch: boolean) => void
7676
refreshing: boolean
@@ -267,6 +267,7 @@ export interface Path {
267267
export type RefreshOptions = {
268268
checkForUpdates?: boolean
269269
fullRefresh?: boolean
270+
library?: Runner
270271
runInBackground?: boolean
271272
}
272273

0 commit comments

Comments
 (0)