Replace the 'game-launch' signal with direct calls.

Mostly using the application to provide a default UI delegate.
This commit is contained in:
Daniel Johnson 2024-01-14 07:01:08 -05:00 committed by Mathieu Comandon
parent ee9738f320
commit 19ff134fb3
10 changed files with 13 additions and 16 deletions

View file

@ -11,7 +11,7 @@ import time
from gettext import gettext as _
from typing import cast
from gi.repository import GLib, GObject, Gtk
from gi.repository import GLib, GObject, Gtk, Gio
from lutris import settings
from lutris.command import MonitoredCommand
@ -57,7 +57,6 @@ class Game(GObject.Object):
# fix merged Dec 2020, but we support older GNOME!
"game-error": (GObject.SIGNAL_RUN_LAST, bool, (object,)),
"game-unhandled-error": (GObject.SIGNAL_RUN_FIRST, None, (object,)),
"game-launch": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-start": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-started": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-stop": (GObject.SIGNAL_RUN_FIRST, None, ()),
@ -673,7 +672,10 @@ class Game(GObject.Object):
return True
@watch_game_errors(game_stop_result=False)
def launch(self, launch_ui_delegate):
def launch(self, launch_ui_delegate=None):
if not launch_ui_delegate:
launch_ui_delegate = Gio.Application.get_default().launch_ui_delegate
"""Request launching a game. The game may not be installed yet."""
if not self.check_launchable():
logger.error("Game is not launchable")

View file

@ -246,7 +246,7 @@ class GameActions(BaseGameActions):
for game in self.games:
if game.is_installed and game.is_db_stored:
if not self.application.is_game_running_by_id(game.id):
game.launch(self.window)
game.launch(launch_ui_delegate=self.window)
def get_running_games(self):
running_games = []

View file

@ -79,7 +79,6 @@ class Application(Gtk.Application):
# established; this will apply to all connections from this point forward.
init_exception_backstops()
GObject.add_emission_hook(Game, "game-launch", self.on_game_launch)
GObject.add_emission_hook(Game, "game-start", self.on_game_start)
GObject.add_emission_hook(Game, "game-stop", self.on_game_stop)
GObject.add_emission_hook(Game, "game-install", self.on_game_install)
@ -784,10 +783,6 @@ class Application(Gtk.Application):
self.set_tray_icon()
return True
def on_game_launch(self, game):
game.launch(self.launch_ui_delegate)
return True # Return True to continue handling the emission hook
def on_game_start(self, game):
self.running_games.append(game)
if settings.read_setting("hide_client_on_game_start") == "True":

View file

@ -216,7 +216,7 @@ class ImportGameDialog(ModelessDialog):
launch_button.connect("clicked", self.on_launch_clicked, game)
def on_launch_clicked(self, _button, game):
game.emit("game-launch")
game.launch()
self.destroy()
def display_existing_game_info(self, filename, game):

View file

@ -909,7 +909,7 @@ class InstallerWindow(ModelessDialog,
self.on_cancel_clicked(button)
game = Game(self.interpreter.installer.game_id)
if game.is_db_stored:
game.emit("game-launch")
game.launch()
else:
logger.error("Game has no ID, launch button should not be drawn")

View file

@ -1112,7 +1112,7 @@ class LutrisWindow(Gtk.ApplicationWindow,
if game_id:
game = Game(game_id)
if game.is_installed:
game.emit("game-launch")
game.launch(launch_ui_delegate=self)
else:
game.emit("game-install")

View file

@ -106,7 +106,7 @@ class BaseService(GObject.Object):
"""Launch the game client"""
launcher = self.get_launcher()
if launcher:
launcher.emit("game-launch")
launcher.launch()
def is_launchable(self):
if self.client_installer:

View file

@ -173,7 +173,7 @@ class EAAppService(OnlineService):
def run(self):
db_game = get_game_by_field(self.client_installer, "slug")
game = Game(db_game["id"])
game.emit("game-launch")
game.launch()
def is_launchable(self):
return get_game_by_field(self.client_installer, "slug")

View file

@ -194,7 +194,7 @@ class EpicGamesStoreService(OnlineService):
def run(self):
egs = get_game_by_field(self.client_installer, "slug")
egs_game = Game(egs["id"])
egs_game.emit("game-launch")
egs_game.launch()
def is_launchable(self):
return get_game_by_field(self.client_installer, "slug")

View file

@ -164,7 +164,7 @@ class OriginService(OnlineService):
def run(self):
db_game = get_game_by_field(self.client_installer, "slug")
game = Game(db_game["id"])
game.emit("game-launch")
game.launch()
def is_launchable(self):
return get_game_by_field(self.client_installer, "slug")