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

Conversation

mtkennerly
Copy link
Contributor

This adds two environment variables when launching games: HEROIC_APP_NAME and HEROIC_APP_STORE. Wrapper commands can use these to look up the app info in the Heroic config (e.g., to get the title or Wine prefix for save backup purposes, in my case).

I tested this on Windows 11 with GOG and Epic. I don't have any Amazon games, so I wasn't able to test that.

In order to test on my system, I made the WrappersTable display on Windows (which I'd like to submit in a separate PR after some testing), then configured a wrapper as a Python script. Main interesting part of the script:

path = Path("C:/tmp/script.log")

with path.open("a") as f:
    f.write(f"{sys.argv}\n")
    for k, v in os.environ.items():
        if k.startswith("HEROIC_"):
            f.write(f"{k} = {v}\n")

I verified that the new environment variables were written out to the log file:

['C:/tmp/script.py', 'C:\\Users\\mtken\\Games\\Heroic\\Dead Cells\\deadcells.exe']
HEROIC_APP_NAME = 1237807960
HEROIC_APP_STORE = gog

['C:/tmp/script.py', 'C:\\Users\\mtken\\Games\\Heroic\\CaveStoryPlus\\CaveStory+.exe', '-AUTH_LOGIN=unused', '-AUTH_PASSWORD=<redacted>', '-AUTH_TYPE=exchangecode', '-epicapp=1dea8a6ddb544842a58e4b5c8675ff58', '-epicenv=Prod', '-EpicPortal', '-epicusername=<redacted>', '-epicuserid=<redacted>', '-epiclocale=en', '-epicsandboxid=78473822f724474d8e436f6bde735623']
HEROIC_APP_NAME = 1dea8a6ddb544842a58e4b5c8675ff58
HEROIC_APP_STORE = epic

Use the following Checklist if you have changed something on the Backend or Frontend:

  • Tested the feature and it's working on a current and clean install.
  • Tested the main App features and they are still working on a current and clean install. (Login, Install, Play, Uninstall, Move games, etc.)
  • Created / Updated Tests (If necessary)
  • Created / Updated documentation (If necessary)

I think these environment variables should be documented, but I'm not sure where that information belongs.

@imLinguin
Copy link
Member

Looks good overall, could you also add it for sideload runner? It might not be useful for your use case, but it's good to have it consistent

@mtkennerly
Copy link
Contributor Author

@imLinguin Updated in 8db11ac :)

I changed HEROIC_APP_STORE to HEROIC_APP_SOURCE since "store" doesn't make as much sense for sideloaded apps.

@imLinguin imLinguin added the pr:ready-for-review Feature-complete, ready for the grind! :P label Aug 11, 2023
@imLinguin imLinguin requested review from a team, arielj, flavioislima, CommandMC, Nocccer and imLinguin and removed request for a team August 11, 2023 11:54
@imLinguin imLinguin added this to the 2.9.2 milestone Aug 31, 2023
@@ -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.

Comment on lines 468 to 474
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.

Copy link
Collaborator

@Nocccer Nocccer left a comment

Choose a reason for hiding this comment

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

Overall looks good.
I left some suggestion/question.

Comment on lines +320 to +333
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
}
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.

@Nocccer Nocccer changed the title Add environment variables for use by wrappers [Feature]: Add environment variables for use by wrappers Sep 4, 2023
@Nocccer Nocccer changed the title [Feature]: Add environment variables for use by wrappers [Improv]: Add environment variables for use by wrappers Sep 4, 2023
Copy link
Member

@flavioislima flavioislima left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for that!

@flavioislima flavioislima merged commit a18a3bf into Heroic-Games-Launcher:main Sep 5, 2023
@mtkennerly mtkennerly deleted the feature/wrapper-env-info branch September 6, 2023 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:ready-for-review Feature-complete, ready for the grind! :P
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants