Use Popen for spawning games again

This commit is contained in:
kramo
2023-05-20 19:53:54 +02:00
parent 48685d2591
commit 0074ef56d4
2 changed files with 23 additions and 23 deletions

View File

@@ -18,7 +18,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import shlex
from time import time
from gi.repository import Adw, Gio, GLib, Gtk
@@ -71,7 +70,7 @@ class DetailsWindow(Adw.Window):
self.name.set_text(self.game.name)
if self.game.developer:
self.developer.set_text(self.game.developer)
self.executable.set_text(shlex.join(self.game.executable))
self.executable.set_text(" ".join(self.game.executable))
self.apply_button.set_label(_("Apply"))
self.game_cover.new_cover(self.game.get_cover_path())
@@ -130,21 +129,7 @@ class DetailsWindow(Adw.Window):
final_name = self.name.get_text()
final_developer = self.developer.get_text()
final_executable = self.executable.get_text()
try:
# Attempt to parse using shell parsing rules (doesn't verify executable existence).
final_executable_split = shlex.split(
final_executable, comments=False, posix=True
)
except ValueError as exception:
create_dialog(
self,
_("Couldn't Add Game")
if not self.game
else _("Couldn't Apply Preferences"),
f'{_("Executable")}: {exception}.',
)
return
final_executable_split = final_executable.split()
if not self.game:
if final_name == "":

View File

@@ -19,10 +19,12 @@
import json
import os
import shlex
import subprocess
from pathlib import Path
from time import time
from gi.repository import Adw, Gio, GLib, Gtk
from gi.repository import Adw, Gio, Gtk
from .game_cover import GameCover
@@ -175,15 +177,28 @@ class Game(Gtk.Box):
self.last_played = int(time())
self.save()
argv = (
("flatpak-spawn", "--host", *self.executable) # Flatpak
args = " ".join(
[
"flatpak-spawn",
"--host",
"/bin/sh",
"-c",
shlex.quote(" ".join(self.executable)),
]
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
else self.executable # Others
else self.executable
)
GLib.spawn_async(
argv, working_directory=str(Path.home()), flags=GLib.SpawnFlags.SEARCH_PATH
print(args)
subprocess.Popen(
args,
cwd=Path.home(),
shell=True,
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"):
self.app.quit()