Skip to content
Open
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
21 changes: 12 additions & 9 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import {
initStoreManagers,
libraryManagerMap
} from './storeManagers'
import type { LibraryManager } from 'common/types/game_manager'
import {
setGameOverrides,
getGameOverrides,
Expand Down Expand Up @@ -906,16 +907,18 @@ if (existsSync(legendaryInstalled)) {
})
}

addHandler('refreshLibrary', async (e, library?) => {
if (library !== undefined && library !== 'all') {
await libraryManagerMap[library].refresh()
} else {
const allRefreshPromises = []
for (const manager of Object.values(libraryManagerMap)) {
allRefreshPromises.push(manager.refresh())
}
await Promise.allSettled(allRefreshPromises)
addHandler('refreshLibrary', async (e, { library, localOnly } = {}) => {
async function doRefresh(manager: LibraryManager) {
if (localOnly && manager.refreshLocal) return manager.refreshLocal()
return manager.refresh()
}

const managers =
library !== undefined && library !== 'all'
? [libraryManagerMap[library]]
: Object.values(libraryManagerMap)

await Promise.allSettled(managers.map(doRefresh))
})

// get pid/tid on launch and inject
Expand Down
33 changes: 27 additions & 6 deletions src/backend/storeManagers/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,42 @@ export default class LegendaryLibraryManager implements LibraryManager {
}

await this.refreshLegendary()
const arr = await this.applyLocalData()
logInfo(
['Game list updated, got', `${arr.length}`, 'games & DLCs'],
LogPrefix.Legendary
)
return this.defaultExecResult
}

/**
* Refresh games in the user's library using only local data, without network calls.
*/
async refreshLocal(): Promise<void> {
logInfo('Refreshing library locally...', LogPrefix.Legendary)
const arr = await this.applyLocalData()
logInfo(
['Game list updated locally, got', `${arr.length}`, 'games & DLCs'],
LogPrefix.Legendary
)
}

/**
* Load local game data into the library store.
*
* @returns Array of GameInfo objects.
*/
private async applyLocalData(): Promise<GameInfo[]> {
this.loadGamesInAccount()
this.refreshInstalled()

try {
await this.loadAll()
} catch (error) {
logError(error, LogPrefix.Legendary)
}
const arr = Array.from(library.values())
libraryStore.set('library', arr)
logInfo(
['Game list updated, got', `${arr.length}`, 'games & DLCs'],
LogPrefix.Legendary
)
return this.defaultExecResult
return arr
}

getListOfGames() {
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ export type RefreshOptions = {
fullRefresh?: boolean
library?: Runner | 'all'
runInBackground?: boolean
localOnly?: boolean
}

export interface WineVersionInfo extends VersionInfo {
Expand Down
1 change: 1 addition & 0 deletions src/common/types/game_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface GameManager {
export interface LibraryManager {
init: () => Promise<void>
refresh: () => Promise<ExecResult | null>
refreshLocal?: () => Promise<void>
getGameInfo: (appName: string, forceReload?: boolean) => GameInfo | undefined
getInstallInfo: (
appName: string,
Expand Down
5 changes: 4 additions & 1 deletion src/common/types/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ interface AsyncIPCFunctions {
requestAppSettings: () => AppSettings
requestGameSettings: (appName: string) => Promise<GameSettings>
writeConfig: (args: { appName: string; config: Partial<AppSettings> }) => void
refreshLibrary: (library?: Runner | 'all') => Promise<void>
refreshLibrary: (options?: {
library?: Runner | 'all'
localOnly?: boolean
}) => Promise<void>
launch: (args: LaunchParams) => StatusPromise
openDialog: (args: OpenDialogOptions) => Promise<string | false>
install: (args: InstallParams) => Promise<void>
Expand Down
18 changes: 11 additions & 7 deletions src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class GlobalState extends PureComponent<Props> {
let gogLibrary = this.loadGOGLibrary(overrides)
if (gog.username && (!gogLibrary.length || !gog.library.length)) {
window.api.logInfo('No cache found, getting data from gog...')
await window.api.refreshLibrary('gog')
await window.api.refreshLibrary({ library: 'gog' })
gogLibrary = this.loadGOGLibrary(overrides)
}

Expand All @@ -731,15 +731,15 @@ class GlobalState extends PureComponent<Props> {
zoomLibrary = this.loadZoomLibrary(overrides)
if (zoom.username && (!zoomLibrary.length || !zoom.library.length)) {
window.api.logInfo('No cache found, getting data from zoom...')
await window.api.refreshLibrary('zoom')
await window.api.refreshLibrary({ library: 'zoom' })
zoomLibrary = this.loadZoomLibrary(overrides)
}
}

let amazonLibrary = nileLibraryStore.get('library', [])
if (amazon.user_id && (!amazonLibrary.length || !amazon.library.length)) {
window.api.logInfo('No cache found, getting data from nile...')
await window.api.refreshLibrary('nile')
await window.api.refreshLibrary({ library: 'nile' })
amazonLibrary = this.loadAmazonLibrary(overrides)
}

Expand Down Expand Up @@ -779,7 +779,8 @@ class GlobalState extends PureComponent<Props> {
refreshLibrary = async ({
checkForUpdates,
runInBackground = true,
library = undefined
library = undefined,
localOnly = false
}: RefreshOptions): Promise<void> => {
if (this.state.refreshing) return

Expand All @@ -789,7 +790,7 @@ class GlobalState extends PureComponent<Props> {
})
window.api.logInfo(`Refreshing ${library} Library`)
try {
await window.api.refreshLibrary(library)
await window.api.refreshLibrary({ library, localOnly })
return await this.refresh(library, checkForUpdates)
} catch (error) {
window.api.logError(`Library refresh failed: ${String(error)}`)
Expand Down Expand Up @@ -858,7 +859,6 @@ class GlobalState extends PureComponent<Props> {
const updatedGamesUpdates = gameUpdates.filter(
(game) => game !== appName
)
// This avoids calling legendary again before the previous process is killed when canceling
this.refreshLibrary({
checkForUpdates: true,
runInBackground: true,
Expand All @@ -872,7 +872,11 @@ class GlobalState extends PureComponent<Props> {
})
}

this.refreshLibrary({ runInBackground: true, library: runner })
this.refreshLibrary({
runInBackground: true,
library: runner,
localOnly: runner === 'legendary'
})

this.setState({ libraryStatus: newLibraryStatus })
}
Expand Down
Loading