Skip to content

[Feature] Configure scripts to run before and after a game is launched #3565

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 13 commits into from
Mar 31, 2024

Conversation

arielj
Copy link
Collaborator

@arielj arielj commented Feb 13, 2024

This PR closes #2507. This can be used to change keyboard layout, screen resolution, or trigger any script the user wants to.

This PR adds 2 configuration options for games to set a script that would run before the game is launched, and one that would run after the game closes:

image

The code will wait for the script to exit before continuing with the launching of the game, so if something should run in the background in parallel to the game it must be handled by the script itself. For example, in bash:

#!/bin/bash

echo "this runs before the game" # this is sync
bash ./another-script.bash & # note the `&` at the end, this will run in parallel and finish when it needs to
echo "this also runs before the game" # this is sync too

With a file like this, Heroic will process the first and last line and proceed to launch the game. It will also process the second line but it won't wait for it to finish, so make sure the synchronous code exits and doesn't leave Heroic waiting forever.

Note that scripts are run in the context of the install directory of the game (working directory is set to the install_path of the game).

I only tested this on linux, so any feedback is welcomed, specially on windows.

I imagine the must will have to be accessible in the Flatpak's permissions if using Heroic flatpak.


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)

@arielj arielj added the pr:ready-for-review Feature-complete, ready for the grind! :P label Feb 13, 2024
@arielj arielj requested review from a team, flavioislima, CommandMC, Etaash-mathamsetty, Nocccer and imLinguin and removed request for a team February 13, 2024 21:36
@arielj arielj requested a review from CommandMC February 17, 2024 14:31
@arielj arielj requested a review from CommandMC February 23, 2024 00:04
@flavioislima
Copy link
Member

About the Settings itself, do you think would be better to do like this:

  • Select Alt EXE
  • Game Arguments
  • New section called Scripts (similar to the wrapper command subtitle
  • Select script to run before
  • Select script to run after

I think would be more intuitive then having script before, exe, script after and then game arguments. Even though they are related, they do not serve the same purpose:
image

@arielj
Copy link
Collaborator Author

arielj commented Mar 16, 2024

@flavioislima just pushed a change re-ordering them

@CommandMC CommandMC mentioned this pull request Mar 16, 2024
4 tasks
@flavioislima flavioislima merged commit 3741f0d into main Mar 31, 2024
@flavioislima flavioislima deleted the before-after-scripts branch March 31, 2024 21:22
@Heroic-Games-Launcher Heroic-Games-Launcher locked and limited conversation to collaborators Mar 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

Best way to run something before and after e.g. changing keyboard layout
3 participants