Skip to content
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

[Fix] Check for game updates before launch #1335

Merged
merged 3 commits into from
May 18, 2022
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
8 changes: 6 additions & 2 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ class LegendaryGame extends Game {
return res
}

public async launch(launchArguments = ''): Promise<LaunchResult> {
public async launch(launchArguments: string): Promise<LaunchResult> {
console.log('launch', { launchArguments })

flavioislima marked this conversation as resolved.
Show resolved Hide resolved
const gameSettings =
GameConfig.get(this.appName).config ||
(await GameConfig.get(this.appName).getSettings())
Expand Down Expand Up @@ -572,6 +574,7 @@ class LegendaryGame extends Game {
steamRuntime
)
}

// These options are required on both Windows and Mac
commandParts = [
'launch',
Expand Down Expand Up @@ -623,7 +626,8 @@ class LegendaryGame extends Game {
offlineFlag,
...wineFlag,
...winePrefixFlag,
launcherArgs
launcherArgs,
launchArguments
]
}
const command = getLegendaryCommand(commandParts, commandEnv, wrappers)
Expand Down
52 changes: 27 additions & 25 deletions src/helpers/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,43 +249,45 @@ type LaunchOptions = {
t: TFunction<'gamepage'>
launchArguments?: string
runner: Runner
hasUpdate: boolean
}

const launch = async ({
appName,
t,
launchArguments,
runner
}: LaunchOptions): Promise<void> =>
ipcRenderer
runner,
hasUpdate
}: LaunchOptions): Promise<void> => {
if (hasUpdate) {
const args = {
buttons: [t('gamepage:box.yes'), t('box.no')],
message: t('gamepage:box.update.message'),
title: t('gamepage:box.update.title')
}

const { response } = await ipcRenderer.invoke('openMessageBox', args)

if (response === 0) {
return updateGame(appName, runner)
}

return ipcRenderer.invoke('launch', {
appName,
runner,
launchArguments: runner === 'legendary' ? '--skip-version-check' : ''
flavioislima marked this conversation as resolved.
Show resolved Hide resolved
})
}

return ipcRenderer
.invoke('launch', { appName, launchArguments, runner })
.then(async (err: string | string[]) => {
if (!err) {
return
}

if (
typeof err === 'string' &&
err.includes('ERROR: Game is out of date')
) {
const args = {
buttons: [t('gamepage:box.yes'), t('box.no')],
message: t('gamepage:box.update.message'),
title: t('gamepage:box.update.title')
}

const { response } = await ipcRenderer.invoke('openMessageBox', args)

if (response === 0) {
return updateGame(appName, runner)
}
await ipcRenderer.invoke('launch', {
appName,
runner,
launchArguments: '--skip-version-check'
})
}
return ipcRenderer.invoke('showErrorBox', ['Error', `${err}`])
})
}

const updateGame = async (appName: string, runner: Runner): Promise<void> =>
ipcRenderer.invoke('updateGame', appName, runner)
Expand Down
8 changes: 7 additions & 1 deletion src/screens/Game/GamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,13 @@ export default function GamePage(): JSX.Element | null {
await syncSaves(savesPath, appName)
setIsSyncing(false)
}
await launch({ appName, t, launchArguments, runner: gameInfo.runner })
await launch({
appName,
t,
launchArguments,
runner: gameInfo.runner,
hasUpdate
})

if (autoSyncSaves) {
setIsSyncing(true)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Library/components/GameCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const GameCard = ({
return sendKill(appName, runner)
}
if (isInstalled) {
return launch({ appName, t, runner })
return launch({ appName, t, runner, hasUpdate })
}
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ export class GlobalState extends PureComponent<Props> {
)[0]
if (!currentApp) {
// Add finding a runner for games
return launch({ appName, t, runner })
const hasUpdate = this.state.gameUpdates?.includes(appName)
return launch({ appName, t, runner, hasUpdate })
}
})

Expand Down