From 172e524ba75f5439fdeb2fbe89dfd647e29b5527 Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Sun, 14 Jan 2024 10:05:02 -0500 Subject: [PATCH] Pass in the launch UI delegate explicitly for launch() This would be better with asyncio; we could keep the InstallWindow or whatnot visible until the game starts. As it is, we'll just use the LutrisWindow for this. --- lutris/game.py | 5 +---- lutris/gui/dialogs/game_import.py | 7 +++++-- lutris/gui/installerwindow.py | 7 +++++-- lutris/gui/widgets/sidebar.py | 2 +- lutris/services/base.py | 8 ++++---- lutris/services/ea_app.py | 8 -------- lutris/services/egs.py | 8 -------- lutris/services/origin.py | 8 -------- 8 files changed, 16 insertions(+), 37 deletions(-) diff --git a/lutris/game.py b/lutris/game.py index 4cffe0774..16cc422ec 100644 --- a/lutris/game.py +++ b/lutris/game.py @@ -741,11 +741,8 @@ class Game(GObject.Object): return True @watch_game_errors(game_stop_result=False) - def launch(self, launch_ui_delegate=None): + def launch(self, launch_ui_delegate): """Request launching a game. The game may not be installed yet.""" - if not launch_ui_delegate: - launch_ui_delegate = Gio.Application.get_default().launch_ui_delegate - if not self.check_launchable(): logger.error("Game is not launchable") return False diff --git a/lutris/gui/dialogs/game_import.py b/lutris/gui/dialogs/game_import.py index c91fa4c72..8f778b88f 100644 --- a/lutris/gui/dialogs/game_import.py +++ b/lutris/gui/dialogs/game_import.py @@ -2,7 +2,7 @@ from collections import OrderedDict from copy import deepcopy from gettext import gettext as _ -from gi.repository import GLib, Gtk +from gi.repository import Gio, GLib, Gtk from lutris.config import write_game_config from lutris.database.games import add_game @@ -216,7 +216,10 @@ class ImportGameDialog(ModelessDialog): launch_button.connect("clicked", self.on_launch_clicked, game) def on_launch_clicked(self, _button, game): - game.launch() + # We can't use this window as the delegate because we + # are destroying it. + application = Gio.Application.get_default() + game.launch(application.launch_ui_delegate) self.destroy() def display_existing_game_info(self, filename, game): diff --git a/lutris/gui/installerwindow.py b/lutris/gui/installerwindow.py index 3d03c83c4..2f1a72e09 100644 --- a/lutris/gui/installerwindow.py +++ b/lutris/gui/installerwindow.py @@ -906,12 +906,15 @@ class InstallerWindow(ModelessDialog, def on_launch_clicked(self, button): """Launch a game after it's been installed.""" button.set_sensitive(False) - self.on_cancel_clicked(button) game = Game(self.interpreter.installer.game_id) if game.is_db_stored: - game.launch() + # Since we're closing this window, we can't use + # it as the delegate. + application = Gio.Application.get_default() + game.launch(application.launch_ui_delegate) else: logger.error("Game has no ID, launch button should not be drawn") + self.on_cancel_clicked(button) def on_window_focus(self, _widget, *_args): """Remove urgency hint (flashing indicator) when window receives focus""" diff --git a/lutris/gui/widgets/sidebar.py b/lutris/gui/widgets/sidebar.py index aa59b3566..45b822066 100644 --- a/lutris/gui/widgets/sidebar.py +++ b/lutris/gui/widgets/sidebar.py @@ -152,7 +152,7 @@ class ServiceSidebarRow(SidebarRow): def on_service_run(self, button): """Run a launcher associated with a service""" - self.service.run() + self.service.run(self.get_toplevel()) def on_refresh_clicked(self, button): """Reload the service games""" diff --git a/lutris/services/base.py b/lutris/services/base.py index c402ec074..840763bcc 100644 --- a/lutris/services/base.py +++ b/lutris/services/base.py @@ -102,20 +102,20 @@ class BaseService(GObject.Object): return self._matcher return self.id - def run(self): + def run(self, launch_ui_delegate): """Launch the game client""" launcher = self.get_launcher() if launcher: - launcher.launch() + launcher.launch(launch_ui_delegate) def is_launchable(self): if self.client_installer: - return get_game_by_field(self.client_installer, "slug") + return bool(get_game_by_field(self.client_installer, "slug")) return False def get_launcher(self): if not self.client_installer: - return + return None db_launcher = get_game_by_field(self.client_installer, "slug") if db_launcher: return Game(db_launcher["id"]) diff --git a/lutris/services/ea_app.py b/lutris/services/ea_app.py index 103c8416e..0c558eabe 100644 --- a/lutris/services/ea_app.py +++ b/lutris/services/ea_app.py @@ -170,14 +170,6 @@ class EAAppService(OnlineService): def api_url(self): return "https://api%s.origin.com" % random.randint(1, 4) - def run(self): - db_game = get_game_by_field(self.client_installer, "slug") - game = Game(db_game["id"]) - game.launch() - - def is_launchable(self): - return get_game_by_field(self.client_installer, "slug") - def is_connected(self): return bool(self.access_token) diff --git a/lutris/services/egs.py b/lutris/services/egs.py index 262dc197c..8c93e383b 100644 --- a/lutris/services/egs.py +++ b/lutris/services/egs.py @@ -191,14 +191,6 @@ class EpicGamesStoreService(OnlineService): 'daafbccc737745039dffe53d94fc76cf' ) - def run(self): - egs = get_game_by_field(self.client_installer, "slug") - egs_game = Game(egs["id"]) - egs_game.launch() - - def is_launchable(self): - return get_game_by_field(self.client_installer, "slug") - def is_connected(self): return self.is_authenticated() diff --git a/lutris/services/origin.py b/lutris/services/origin.py index 7bf9ee812..8bc232543 100644 --- a/lutris/services/origin.py +++ b/lutris/services/origin.py @@ -161,14 +161,6 @@ class OriginService(OnlineService): def api_url(self): return "https://api%s.origin.com" % random.randint(1, 4) - def run(self): - db_game = get_game_by_field(self.client_installer, "slug") - game = Game(db_game["id"]) - game.launch() - - def is_launchable(self): - return get_game_by_field(self.client_installer, "slug") - def is_connected(self): return bool(self.access_token)