Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Aims to implement #21, I totally get it if you reject it tho haha.
The whole process is a pain in the ass.
First, the only way I found to get the PID of the process started with cmd is through executing tasklist and filtering for its name. Problem? When you launch a .lnk or use the steam protocol, the name that appears on tasklist is the .exe name. So I had to add "exe_name" as a new field in the config file.
Second, what if you have another instance of that process running before? So I had to check before creating the new process, store the previous PIDs and compare after.
Third, launching with steam:// takes a while, sometimes up to 15s in my computer. This means the new process isn't created until that, so I had to delay the PID search, that's why there's retries in on_timer_timeout().
Last, there's no way I found to get the exit code of a process spawned this way, so relaunching on crash is impossible unless we only allow closing the app through the launcher.
I tested it with a steam game, a .lnk and a regular game and everything seems to work OK.
PD: in theory, execute_with_pipe() gives you access to the stdio of the cmd it opens, but I wasn't able to read or write anything from/to it. Since it's non blocking, my idea was to wait the process by passing /wait, and then echo the %ERRORLEVEL% since it that gives the exit code of the previous process spawned by a cmd. Ideas/contributions are welcome.