Skip to content

Commit

Permalink
[Feat] Pass additional game information to the pre-post launch script…
Browse files Browse the repository at this point in the history
… using environment variables (#3748)

* Pass additional game information (title and executable) to the pre-post launch script using environment variables

* Fix lint error

* Fixed another lint error (and checked lint before commiting again)

* Fixed code style issues

* Added Heroic_ prefix to variables to make it clear they come from Heroic

* Added HEROIC_GAMEINFO_RUNNER to inform about the runner

* Added variables for game id, game prefix and script execution stage. Shortened variables names.

* Code simplification

* Code cleanup
  • Loading branch information
casasfernando authored May 27, 2024
1 parent 8c77906 commit 00cc06a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ async function runBeforeLaunchScript(
`Running script before ${gameInfo.title} (${gameSettings.beforeLaunchScriptPath})\n`
)

return runScriptForGame(gameInfo, gameSettings.beforeLaunchScriptPath)
return runScriptForGame(gameInfo, gameSettings, 'before')
}

async function runAfterLaunchScript(
Expand All @@ -1338,7 +1338,7 @@ async function runAfterLaunchScript(
gameInfo,
`Running script after ${gameInfo.title} (${gameSettings.afterLaunchScriptPath})\n`
)
return runScriptForGame(gameInfo, gameSettings.afterLaunchScriptPath)
return runScriptForGame(gameInfo, gameSettings, 'after')
}

/* Execute script before launch/after exit, wait until the script
Expand All @@ -1365,10 +1365,24 @@ async function runAfterLaunchScript(
*/
async function runScriptForGame(
gameInfo: GameInfo,
scriptPath: string
gameSettings: GameSettings,
scriptStage: 'before' | 'after'
): Promise<boolean | string> {
return new Promise((resolve, reject) => {
const child = spawn(scriptPath, { cwd: gameInfo.install.install_path })
const scriptPath = gameSettings[`${scriptStage}LaunchScriptPath`]
const scriptEnv = {
HEROIC_GAME_APP_NAME: gameInfo.app_name,
HEROIC_GAME_EXEC: gameInfo.install.executable,
HEROIC_GAME_PREFIX: gameSettings.winePrefix,
HEROIC_GAME_RUNNER: gameInfo.runner,
HEROIC_GAME_SCRIPT_STAGE: scriptStage,
HEROIC_GAME_TITLE: gameInfo.title,
...process.env
}
const child = spawn(scriptPath, {
cwd: gameInfo.install.install_path,
env: scriptEnv
})

child.stdout.on('data', (data) => {
appendGamePlayLog(gameInfo, data.toString())
Expand Down

0 comments on commit 00cc06a

Please sign in to comment.