Improve behaviour of Lutris background process

This commit adresses the following issues:
 * Closing the Lutris main window kills games started by Lutris
 * Starting a game using "lutris:rungameid" closes the lutris main window
 * Opening the main window after starting a game with "lutris:rungameid"
   quits Lutris when that game closes.
This commit is contained in:
Manuel Vögele 2018-10-02 11:51:37 +02:00 committed by Mathieu Comandon
parent 3c6a5781e1
commit 7ca5f6c99b
2 changed files with 18 additions and 15 deletions

View file

@ -176,7 +176,7 @@ class Application(Gtk.Application):
self.css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
self.window.present()
GLib.timeout_add(300, self.refresh_status)
@staticmethod
def _print(command_line, string):
@ -274,34 +274,36 @@ class Application(Gtk.Application):
action = 'install'
if action == 'install':
self.window.present()
self.window.on_install_clicked(game_slug=game_slug,
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()
if self.window.is_visible():
logger.info("No game found in library")
else:
logger.info("No game found in library, shutting down")
self.do_shutdown()
return 0
logger.info("Launching %s" % db_game['name'])
# 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'])
# If game is not installed, show the GUI before running. Otherwise leave the GUI closed.
if not db_game['installed']:
self.window.present()
self.window.on_game_run(game_id=db_game['id'])
else:
self.window.present()
return 0
def refresh_status(self):
if self.window.running_game.state == self.window.running_game.STATE_STOPPED:
self.do_shutdown()
return False
if self.window.running_game is None or self.window.running_game.state == self.window.running_game.STATE_STOPPED:
if not self.window.is_visible():
self.do_shutdown()
return False
return True
def get_lutris_action(self, url):

View file

@ -283,6 +283,7 @@ class LutrisWindow(Gtk.ApplicationWindow):
This must be called each time the view is rebuilt.
"""
self.connect('delete-event', lambda *x: self.hide_on_delete())
self.view.connect('game-installed', self.on_game_installed)
self.view.connect("game-activated", self.on_game_run)
self.view.connect("game-selected", self.game_selection_changed)