Skip to content

Allow for separate library refreshes #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,18 @@ ipcMain.handle(

/// IPC handlers begin here.

ipcMain.handle('checkGameUpdates', async () => {
const legendaryUpdates = await LegendaryLibrary.get().listUpdateableGames()
const gogUpdates = await GOGLibrary.get().listUpdateableGames()
return [...legendaryUpdates, ...gogUpdates]
ipcMain.handle('checkGameUpdates', async (event, library?: Runner) => {
switch (library) {
case 'legendary':
return LegendaryLibrary.get().listUpdateableGames()
case 'gog':
return GOGLibrary.get().listUpdateableGames()
default:
return [
...(await LegendaryLibrary.get().listUpdateableGames()),
...(await GOGLibrary.get().listUpdateableGames())
]
}
})

ipcMain.handle('getEpicGamesStatus', async () => isEpicServiceOffline())
Expand Down Expand Up @@ -754,11 +762,21 @@ if (existsSync(installed)) {
})
}

ipcMain.handle('refreshLibrary', async (e, fullRefresh) => {
await Promise.allSettled([
GOGLibrary.get().sync(),
LegendaryLibrary.get().getGames('info', fullRefresh)
])
ipcMain.handle('refreshLibrary', async (e, fullRefresh, library?: Runner) => {
switch (library) {
case 'legendary':
await LegendaryLibrary.get().getGames('info', fullRefresh)
break
case 'gog':
await GOGLibrary.get().sync()
break
default:
await Promise.allSettled([
LegendaryLibrary.get().getGames('info', fullRefresh),
GOGLibrary.get().sync()
])
break
}
})

ipcMain.on('logError', (e, err) => logError(`${err}`, LogPrefix.Frontend))
Expand Down
6 changes: 5 additions & 1 deletion src/components/UI/ActionIcons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ import { useTranslation } from 'react-i18next'
import ContextProvider from 'src/state/ContextProvider'
import FormControl from '../FormControl'
import './index.css'
import { Runner } from 'src/types'

interface Props {
sortDescending: boolean
sortInstalled: boolean
toggleSortDescending: () => void
toggleSortinstalled: () => void
library: Runner
}

export default function ActionIcons({
library,
sortDescending,
toggleSortDescending,
sortInstalled,
Expand Down Expand Up @@ -85,7 +88,8 @@ export default function ActionIcons({
refreshLibrary({
checkForUpdates: true,
fullRefresh: true,
runInBackground: false
runInBackground: false,
library
})
}
>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Game/GameSubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function GamesSubmenu({
})
if (path) {
await renderer.invoke('changeInstallPath', [appName, path, runner])
await refresh()
await refresh(runner)
}
return
}
Expand Down
1 change: 1 addition & 0 deletions src/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function Library(): JSX.Element {
sortDescending={sortDescending}
toggleSortDescending={() => handleSortDescending()}
sortInstalled={sortInstalled}
library={category === 'epic' ? 'legendary' : 'gog'}
toggleSortinstalled={() => handleSortInstalled()}
/>
</div>
Expand Down
27 changes: 16 additions & 11 deletions src/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InstalledInfo,
LibraryTopSectionOptions,
RefreshOptions,
Runner,
WineVersionInfo
} from 'src/types'
import { TFunction, withTranslation } from 'react-i18next'
Expand Down Expand Up @@ -232,12 +233,13 @@ export class GlobalState extends PureComponent<Props> {
this.setState({ libraryTopSection: value })
}

handleSuccessfulLogin = (runner: 'epic' | 'gog') => {
handleSuccessfulLogin = (runner: Runner) => {
this.handleFilter('all')
this.handleCategory(runner)
this.refreshLibrary({
fullRefresh: true,
runInBackground: false
runInBackground: false,
library: runner
})
}

Expand All @@ -253,7 +255,7 @@ export class GlobalState extends PureComponent<Props> {
}
})

this.handleSuccessfulLogin('epic')
this.handleSuccessfulLogin('legendery' as Runner)
}

return response.status
Expand Down Expand Up @@ -289,7 +291,7 @@ export class GlobalState extends PureComponent<Props> {
window.location.reload()
}

refresh = async (checkUpdates?: boolean): Promise<void> => {
refresh = async (library?: Runner, checkUpdates?: boolean): Promise<void> => {
console.log('refreshing')

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

try {
updates = checkUpdates
? await ipcRenderer.invoke('checkGameUpdates')
? await ipcRenderer.invoke('checkGameUpdates', library)
: this.state.gameUpdates
} catch (error) {
ipcRenderer.send('logError', error)
Expand Down Expand Up @@ -338,7 +340,8 @@ export class GlobalState extends PureComponent<Props> {
refreshLibrary = async ({
checkForUpdates,
fullRefresh,
runInBackground = true
runInBackground = true,
library = undefined
}: RefreshOptions): Promise<void> => {
if (this.state.refreshing) return

Expand All @@ -348,11 +351,11 @@ export class GlobalState extends PureComponent<Props> {
})
ipcRenderer.send('logInfo', 'Refreshing Library')
try {
await ipcRenderer.invoke('refreshLibrary', fullRefresh)
await ipcRenderer.invoke('refreshLibrary', fullRefresh, library)
} catch (error) {
ipcRenderer.send('logError', error)
}
this.refresh(checkForUpdates)
this.refresh(library, checkForUpdates)
}

refreshWineVersionInfo = async (fetch: boolean): Promise<void> => {
Expand Down Expand Up @@ -407,7 +410,8 @@ export class GlobalState extends PureComponent<Props> {
appName,
status,
folder,
progress
progress,
runner
}: GameStatus) => {
const { libraryStatus, gameUpdates } = this.state
const currentApp = libraryStatus.filter(
Expand Down Expand Up @@ -440,7 +444,8 @@ export class GlobalState extends PureComponent<Props> {
// This avoids calling legendary again before the previous process is killed when canceling
this.refreshLibrary({
checkForUpdates: true,
runInBackground: true
runInBackground: true,
library: runner
})

storage.setItem(
Expand All @@ -454,7 +459,7 @@ export class GlobalState extends PureComponent<Props> {
})
}

this.refreshLibrary({ runInBackground: true })
this.refreshLibrary({ runInBackground: true, library: runner })
this.setState({ libraryStatus: newLibraryStatus })
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface ContextType {
libraryTopSection: string
handleLibraryTopSection: (value: LibraryTopSectionOptions) => void
platform: NodeJS.Platform | string
refresh: (checkUpdates?: boolean) => Promise<void>
refresh: (library: Runner, checkUpdates?: boolean) => Promise<void>
refreshLibrary: (options: RefreshOptions) => Promise<void>
refreshWineVersionInfo: (fetch: boolean) => void
refreshing: boolean
Expand Down Expand Up @@ -267,6 +267,7 @@ export interface Path {
export type RefreshOptions = {
checkForUpdates?: boolean
fullRefresh?: boolean
library?: Runner
runInBackground?: boolean
}

Expand Down