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 1 commit
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
17 changes: 11 additions & 6 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,13 @@ ipcMain.handle(

/// IPC handlers begin here.

ipcMain.handle('checkGameUpdates', async () => {
const legendaryUpdates = await LegendaryLibrary.get().listUpdateableGames()
const gogUpdates = await GOGLibrary.get().listUpdateableGames()
ipcMain.handle('checkGameUpdates', async (event, libraries) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you should receive a Runner here and then depending on the Runner you call the right one.
Use a switch to make it more scalable. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also have a full parameter to refresh all libraries

const legendaryUpdates = libraries.includes('epic')
? await LegendaryLibrary.get().listUpdateableGames()
: []
const gogUpdates = libraries.includes('gog')
? await GOGLibrary.get().listUpdateableGames()
: []
return [...legendaryUpdates, ...gogUpdates]
})

Expand Down Expand Up @@ -754,10 +758,11 @@ if (existsSync(installed)) {
})
}

ipcMain.handle('refreshLibrary', async (e, fullRefresh) => {
ipcMain.handle('refreshLibrary', async (e, fullRefresh, libraries) => {
await Promise.allSettled([
GOGLibrary.get().sync(),
LegendaryLibrary.get().getGames('info', fullRefresh)
libraries.includes('epic') &&
LegendaryLibrary.get().getGames('info', fullRefresh),
libraries.includes('gog') && GOGLibrary.get().sync()
])
})

Expand Down
7 changes: 5 additions & 2 deletions src/components/UI/ActionIcons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ interface Props {
sortInstalled: boolean
toggleSortDescending: () => void
toggleSortinstalled: () => void
category: string
}

export default function ActionIcons({
sortDescending,
toggleSortDescending,
sortInstalled,
toggleSortinstalled
toggleSortinstalled,
category
}: Props) {
const { t } = useTranslation()
const { refreshLibrary, handleLayout, layout } = useContext(ContextProvider)
Expand Down Expand Up @@ -85,7 +87,8 @@ export default function ActionIcons({
refreshLibrary({
checkForUpdates: true,
fullRefresh: true,
runInBackground: false
runInBackground: false,
libraries: [category]
})
}
>
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}
category={category}
toggleSortinstalled={() => handleSortInstalled()}
/>
</div>
Expand Down
23 changes: 17 additions & 6 deletions src/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export class GlobalState extends PureComponent<Props> {
this.handleCategory(runner)
this.refreshLibrary({
fullRefresh: true,
runInBackground: false
runInBackground: false,
libraries: [runner]
})
}

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

refresh = async (checkUpdates?: boolean): Promise<void> => {
refresh = async (
libraries: string[],
checkUpdates?: boolean
): Promise<void> => {
console.log('refreshing')

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

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

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

refreshWineVersionInfo = async (fetch: boolean): Promise<void> => {
Expand Down Expand Up @@ -531,10 +536,16 @@ export class GlobalState extends PureComponent<Props> {
recentGames
})

const libraries: string[] = [
gogUser && 'gog',
legendaryUser && 'epic'
].filter(Boolean) as string[]

if (legendaryUser || gogUser) {
this.refreshLibrary({
checkForUpdates: true,
fullRefresh: true,
libraries,
runInBackground: Boolean(epic.library.length)
})
}
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: (libraries: string[], 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
libraries?: string[]
runInBackground?: boolean
}

Expand Down