Skip to content
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

Refactor Legendary/GOGDL handling #1092

Merged

Conversation

CommandMC
Copy link
Collaborator

@CommandMC CommandMC commented Mar 11, 2022

This PR unifies every instance of running/invoking Legendary/GOGDL to use one function each (runLegendaryCommand/runGogdlCommand).It improves a few things in the process:

  • process.chdir() is no longer necessary
  • Adding directories to %PATH%/$PATH is no longer necessary
  • Paths with spaces are handled properly (by using the cwd option of spawn)
  • Every Legendary/GOGDL command can now be logged, all it takes is one argument
  • Alternative binaries do not require a restart
  • Some misc fixes/changes
    • Old & unused API removed
    • Download progress is formatted nicer on Linux
    • ExecResult now has an optional fullCommand argument to indicate the exact command that was ran

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.)

Note: Testing was, as usual, done on Linux and Windows. I don't have a Mac, if anyone could test on there, that would be great

@CommandMC CommandMC added the pr:ready-for-review Feature-complete, ready for the grind! :P label Mar 11, 2022
@CommandMC CommandMC mentioned this pull request Mar 12, 2022
2 tasks
@adityaruplaha
Copy link
Contributor

Someone please add this to Project Beans. :P

Thanks for this PR, I wanted to get this done for a while but didn't have the time.

@CommandMC
Copy link
Collaborator Author

CommandMC commented Mar 13, 2022

There's an issue with Linux-native GOG games not installing properly right now. I'm working on it

@CommandMC
Copy link
Collaborator Author

It seems like everything is working now, the only issue is that installing GOG games doesn't get registered properly so you have to press the "Refresh Library" button once.
I honestly can't say why this happens since I haven't really changed that code

electron/config.ts Outdated Show resolved Hide resolved
electron/utils.ts Outdated Show resolved Hide resolved
electron/main.ts Outdated Show resolved Hide resolved
flavioislima
flavioislima previously approved these changes Mar 15, 2022
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.

Tested here for a bit and could not find any bug or issue so looks good.
I believe testing on other platforms and on Flatpak would be good as well. I will try to test on a Mac tomorrow.
Also, @imLinguin would be nice if you could take a look at it as well, especially the GOG part.

But pretty good job with the refactor.
The code is cleaner and more efficient now. Also, more easy to scalate ⚔️

imLinguin
imLinguin previously approved these changes Mar 15, 2022
Copy link
Member

@imLinguin imLinguin left a comment

Choose a reason for hiding this comment

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

I looked at GOG changes. Looks good to me

Comment on lines +185 to +186
installedGamesStore.set('installed', array)
GOGLibrary.get().refreshInstalled()
Copy link
Member

Choose a reason for hiding this comment

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

About bug you mentioned. This might be a race condition we are looking for, since refreshInstalled reads from the same config. Maybe a function to update installed games directly in memory (instead of reading from the same file again) will solve the issue.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could do it like this from now on. Perhaps on another PR:
After refreshing the library on the backend, we send an event to the frontend to refresh the state.
This way we could solve the racing conditions.

This changes every legendary/gogdl-related function to call
runLegendaryCommand/runGogdlCommand. With that, it unifies
the ~3 different approaches used before into one (hopefully)
easy-to-understand function.

This has the added benefit that if this function breaks, it'll
break everywhere. This should prevent a scenario like in the past
few days from happening, as either everything or nothing works.
There were a few unnecessary newlines here that I remove with .trim()
When using a shell, the quotes around paths got removed automatically.
Now with spawn, this no longer happened and apparently
GOGDL wasn't happy about it.
Not sure why this was done like this, seems to still work fine now
This is kinda hacky, but it stops weird things from happening when
starting a download, quitting heroic, and then starting it again
This changes just about all implementations of ExecResult to use
the new error property
electron/config.ts Outdated Show resolved Hide resolved
@flavioislima
Copy link
Member

Tested these changes on a Mac and looks good as well.
The only issue I could find was that after logout the status of the Login Card still shows as logged in. Although I am not sure if this is Mac-specific or if it is related to these changes.


if (logFile) {
child.stdout.on('data', (data: Buffer) => {
appendFileSync(logFile, data.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

Kudos for all the changes, but maybe you shouldn't use sync method. Also, new file handle is created for each chunk. This could lead to blocking of app.

I suggest opening a file once and appending to it.
I suggest creating writeable stream from file and piping output directly to that stream
It would be also nice to use node's readline module. This would enable further changes to fix the atrocity that is the requestGameProgress handler: https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/blob/main/electron/main.ts#L1100

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that this definitely needs improvement, but I'm afraid that I don't know enough about the language yet to make these changes + they don't really fit into this PR. I'd say we merge this for now & then we can look into improving it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, it can be added later.

@flavioislima flavioislima merged commit 756a1e7 into Heroic-Games-Launcher:main Mar 18, 2022
@CommandMC CommandMC deleted the child_proc_experiments branch March 18, 2022 22:29
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.

None yet

5 participants