Skip to content

[Improv]: Add environment variables for use by wrappers #2969

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
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 31 additions & 0 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
GameInfo,
Runner,
EnviromentVariable,
WrapperEnv,
WrapperVariable,
ExecResult,
GameSettings,
Expand Down Expand Up @@ -275,6 +276,7 @@ async function prepareWineLaunch(
/**
* Maps general settings to environment variables
* @param gameSettings The GameSettings to get the environment variables for
* @param wrapperEnv The wrapper info to be added into the environment variables
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @param wrapperEnv The wrapper info to be added into the environment variables

Seems like this was moved to its own function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I originally tried adding the functionality here, but realized it worked better separate and forgot to reset the documentation. Fixed in 87ee893.

* @returns A big string of environment variables, structured key=value
*/
function setupEnvVars(gameSettings: GameSettings) {
Expand Down Expand Up @@ -305,6 +307,34 @@ function setupEnvVars(gameSettings: GameSettings) {
return ret
}

/**
* Maps launcher info to environment variables for consumption by wrappers
* @param wrapperEnv The info to be added into the environment variables
* @returns Environment variables
*/
function setupWrapperEnvVars(wrapperEnv: WrapperEnv) {
const ret: Record<string, string> = {}

ret.HEROIC_APP_NAME = wrapperEnv.appName

switch (wrapperEnv.appRunner) {
case 'gog':
ret.HEROIC_APP_SOURCE = 'gog'
break
case 'legendary':
ret.HEROIC_APP_SOURCE = 'epic'
break
case 'nile':
ret.HEROIC_APP_SOURCE = 'amazon'
break
case 'sideload':
ret.HEROIC_APP_SOURCE = 'sideload'
break
}
Comment on lines +320 to +333
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not ?

Suggested change
switch (wrapperEnv.appRunner) {
case 'gog':
ret.HEROIC_APP_SOURCE = 'gog'
break
case 'legendary':
ret.HEROIC_APP_SOURCE = 'epic'
break
case 'nile':
ret.HEROIC_APP_SOURCE = 'amazon'
break
case 'sideload':
ret.HEROIC_APP_SOURCE = 'sideload'
break
}
ret.HEROIC_APP_SOURCE = wrappernEnv.appRunner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking there could be a case in the future where it may help to distinguish the runner and the source, like if you could choose two different runners for the same store or if one runner supported multiple stores. Not sure if that's a valid/realistic concern given Heroic's design goals.

I added a HEROIC_APP_RUNNER env var in e78e680. Just let me know if you'd prefer to have HEROIC_APP_SOURCE removed as well.


return ret
}

/**
* Maps Wine-related settings to environment variables
* @param gameSettings The GameSettings to get the environment variables for
Expand Down Expand Up @@ -982,6 +1012,7 @@ export {
launchCleanup,
prepareWineLaunch,
setupEnvVars,
setupWrapperEnvVars,
setupWineEnvVars,
setupWrappers,
runWineCommand,
Expand Down
11 changes: 8 additions & 3 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
prepareWineLaunch,
runWineCommand as runWineCommandUtil,
setupEnvVars,
setupWrapperEnvVars,
setupWrappers
} from '../../launcher'
import {
Expand Down Expand Up @@ -464,9 +465,13 @@ export async function launch(
? ['--override-exe', gameSettings.targetExe]
: []

let commandEnv = isWindows
? process.env
: { ...process.env, ...setupEnvVars(gameSettings) }
let commandEnv = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: 'gog' })
}
if (!isWindows) {
commandEnv = { ...commandEnv, ...setupEnvVars(gameSettings) }
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let commandEnv = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: 'gog' })
}
if (!isWindows) {
commandEnv = { ...commandEnv, ...setupEnvVars(gameSettings) }
}
let commandEnv = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: 'gog' }),
...(isWindows ? {} : setupEnvVars(gameSettings))
}

This feels a little cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Updated in 5d1a6fe.


const wrappers = setupWrappers(
gameSettings,
Expand Down
11 changes: 8 additions & 3 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
prepareLaunch,
prepareWineLaunch,
setupEnvVars,
setupWrapperEnvVars,
setupWrappers,
launchCleanup,
getRunnerCallWithoutCredentials,
Expand Down Expand Up @@ -822,9 +823,13 @@ export async function launch(

const languageCode = gameSettings.language || configStore.get('language', '')

let commandEnv = isWindows
? process.env
: { ...process.env, ...setupEnvVars(gameSettings) }
let commandEnv = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: 'legendary' })
}
if (!isWindows) {
commandEnv = { ...commandEnv, ...setupEnvVars(gameSettings) }
}

const wrappers = setupWrappers(
gameSettings,
Expand Down
11 changes: 8 additions & 3 deletions src/backend/storeManagers/nile/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
prepareLaunch,
prepareWineLaunch,
setupEnvVars,
setupWrapperEnvVars,
setupWrappers
} from 'backend/launcher'
import { appendFileSync, existsSync } from 'graceful-fs'
Expand Down Expand Up @@ -344,9 +345,13 @@ export async function launch(
? ['--override-exe', gameSettings.targetExe]
: []

let commandEnv = isWindows
? process.env
: { ...process.env, ...setupEnvVars(gameSettings) }
let commandEnv = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: 'nile' })
}
if (!isWindows) {
commandEnv = { ...commandEnv, ...setupEnvVars(gameSettings) }
}

const wrappers = setupWrappers(
gameSettings,
Expand Down
8 changes: 7 additions & 1 deletion src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
prepareLaunch,
runWineCommand,
setupEnvVars,
setupWrapperEnvVars,
setupWrappers
} from '../../launcher'
import { access, chmod } from 'fs/promises'
Expand Down Expand Up @@ -131,7 +132,12 @@ export async function launchGame(
})
return false
}
const env = { ...process.env, ...setupEnvVars(gameSettings) }

const env = {
...process.env,
...setupWrapperEnvVars({ appName, appRunner: runner }),
...setupEnvVars(gameSettings)
}

// Native
if (isNative) {
Expand Down
5 changes: 5 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ export interface WrapperVariable {
args: string
}

export interface WrapperEnv {
appName: string
appRunner: Runner
}

type AntiCheat =
| 'Arbiter'
| 'BattlEye'
Expand Down