Repository: lutris/lutris

Issue:
Close Lutris after CLI rungame/rungameid
When using `lutris lutris:rungame/%`, the Lutris window stays open after the game has quit. Would be great to:

1. Not have Lutris pop up at all
2. Quit Lutris after it was run

Originally reported in https://github.com/RobLoach/lutris-kodi-addon/issues/14 by @solbero . Another solution might be a `--no-gui` option or something.

## Testing

1. Open up your terminal
2. Run `lutris lutris:rungame/tuxracer`
3. Lutris window pops up and runs the game
4. When you quit the game, Lutris stays open.


Discussion:
Implementing a feature which is similar in behaviour to Steam’s `steam steam://rungameid/####` would be a boon for people using Lutris on a HTPC. When launching games with the above command, the Steam GUI is never shown on screen.

As @RobLoach points out, as of now the Lutris GUI is left open after the user exits a game. For HTPC usage this is not ideal if the user is using a gamepad for navigation and gaming. As implemented, the user has to use a mouse and keyboard or simulate a mouse with the gamepad to close the GUI or assign ALT+F4 to a gamepad button.
I would also love a no gui mode. Any plans to include such a feature?

@lefty420 this specific issue will be fixed in next release, other than that, there are no immediate plans to add other command line only features.
Thanks a lot :) That would make a massive difference when loading from other front ends. Well I can keep the keyboard in the draw at least ;)

Awesome! Can’t wait for next release. 
This would be very nice. Closely related, I think Lutris should immediately exit if the given game does not exist, instead of showing the UI and a traceback in console.

Resolving patch:
diff --git a/lutris/gui/application.py b/lutris/gui/application.py
--- a/lutris/gui/application.py
+++ b/lutris/gui/application.py
@@ -267,11 +267,32 @@ def do_command_line(self, command_line):
                                            installer_file=installer_file,
                                            revision=revision)
         elif action in ('rungame', 'rungameid'):
+            if not db_game or not db_game['id']:
+                logger.info("No game found in library, shutting down")
+                self.do_shutdown()
+                return 0
+            
             logger.info("Launching %s" % db_game['name'])
-            self.window.on_game_run(game_id=db_game['id'])
+
+            # If game is installed, run it without showing the GUI
+            # Also set a timer to shut down lutris when game ends
+            if db_game['installed']:
+                self.window.hide()
+                self.window.on_game_run(game_id=db_game['id'])
+                GLib.timeout_add(300, self.refresh_status)
+            # If game is not installed, show the GUI
+            else:
+                self.window.on_game_run(game_id=db_game['id'])
+
 
         return 0
 
+    def refresh_status(self):
+        if self.window.running_game.state == self.window.running_game.STATE_STOPPED:
+            self.do_shutdown()
+            return False
+        return True
+
     def get_lutris_action(self, url):
         installer_info = {
             'game_slug': None,


Test patch: