diff --git a/src/game.py b/src/game.py index dc29f24..60d1336 100644 --- a/src/game.py +++ b/src/game.py @@ -18,8 +18,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os +import subprocess +import sys -from gi.repository import GdkPixbuf, Gtk +from gi.repository import GdkPixbuf, Gio, Gtk @Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/game.ui") @@ -64,6 +66,20 @@ class game(Gtk.Box): # pylint: disable=invalid-name self.event_contoller_motion.connect("leave", self.hide_play) self.menu_button.get_popover().connect("notify::visible", self.hide_play) + def launch(self): + # The host environment vars are automatically passed through by Popen. + subprocess.Popen( + ["flatpak-spawn", "--host", *self.executable] # Flatpak + if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges" + else self.executable # Windows + if os.name == "nt" + else self.executable, # Linux/Others + start_new_session=True, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0, + ) + if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"): + sys.exit() + def get_cover(self): # If the cover is already in memory, return diff --git a/src/main.py b/src/main.py index 17eb53b..ce5c3ff 100644 --- a/src/main.py +++ b/src/main.py @@ -34,7 +34,6 @@ from .create_details_window import create_details_window from .get_games import get_games from .heroic_parser import heroic_parser from .preferences import PreferencesWindow -from .run_command import run_command from .save_games import save_games from .steam_parser import steam_parser from .toggle_hidden import toggle_hidden @@ -158,7 +157,7 @@ class CartridgesApplication(Adw.Application): data["last_played"] = int(time.time()) save_games({game_id: data}) - run_command(self.win.games[self.win.active_game_id].executable) + self.win.games[game_id].launch() self.win.update_games([game_id]) diff --git a/src/meson.build b/src/meson.build index 4d67371..ab407c0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,7 +25,6 @@ cartridges_sources = [ 'utils/steam_parser.py', 'utils/heroic_parser.py', 'utils/bottles_parser.py', - 'utils/run_command.py', 'utils/get_games.py', 'utils/save_games.py', 'utils/save_cover.py', diff --git a/src/utils/run_command.py b/src/utils/run_command.py deleted file mode 100644 index 4729284..0000000 --- a/src/utils/run_command.py +++ /dev/null @@ -1,40 +0,0 @@ -# run_command.py -# -# Copyright 2022-2023 kramo -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import os -import shlex -import subprocess -import sys - -from gi.repository import Gio - - -def run_command(executable): - # The host environment vars are automatically passed through by Popen. - subprocess.Popen( - ["flatpak-spawn", "--host", *executable] # Flatpak - if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges" - else executable # Windows - if os.name == "nt" - else executable, # Linux/Others - start_new_session=True, - creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0, - ) - if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"): - sys.exit()