Skip to content

Commit

Permalink
fix: native runners detection in flatpak (#53)
Browse files Browse the repository at this point in the history
* fix: native runners detection in flatpak

* use chdir for working directory
  • Loading branch information
imLinguin authored Sep 10, 2024
1 parent 80269d2 commit 151f05f
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions gogdl/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ def get_flatpak_command(id: str) -> list[str]:
new_process_command = []
process_command = ["flatpak", "info", id]
if os.path.exists("/.flatpak-info"):
spawn_test = subprocess.run(["flatpak-spawn", "--host" "ls"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if spawn_test.returncode == 0:
new_process_command = ["flatpak-spawn", "--host"]
process_command = new_process_command + process_command
try:
spawn_test = subprocess.run(["flatpak-spawn", "--host", "ls"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except FileNotFoundError:
return []
if spawn_test.returncode != 0:
return []

output = subprocess.run(process_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if output.returncode == 0:
return new_process_command + ["flatpak", "run", id]
new_process_command = ["flatpak-spawn", "--host"]
process_command = new_process_command + process_command

try:
output = subprocess.run(process_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if output.returncode == 0:
return new_process_command + ["flatpak", "run", id]

except FileNotFoundError:
pass
return []


Expand Down Expand Up @@ -76,7 +85,12 @@ def launch(arguments, unknown_args):

if not os.path.exists(executable):
executable = get_case_insensitive_name(executable)
# Handle case sensitive file systems
if not os.path.exists(working_dir):
working_dir = get_case_insensitive_name(working_dir)

os.chdir(working_dir)

if sys.platform != "win32" and arguments.platform == 'windows' and not arguments.override_exe:
if "scummvm.exe" in executable.lower():
flatpak_scummvm = get_flatpak_command("org.scummvm.ScummVM")
Expand Down Expand Up @@ -105,6 +119,8 @@ def launch(arguments, unknown_args):
if arguments.override_exe:
command.append(arguments.override_exe)
working_dir = os.path.split(arguments.override_exe)[0]
if not os.path.exists(working_dir):
working_dir = get_case_insensitive_name(working_dir)
elif executable:
command.append(executable)
command.extend(launch_arguments)
Expand All @@ -115,9 +131,13 @@ def launch(arguments, unknown_args):
if arguments.override_exe:
command.append(arguments.override_exe)
working_dir = os.path.split(arguments.override_exe)[0]
# Handle case sensitive file systems
if not os.path.exists(working_dir):
working_dir = get_case_insensitive_name(working_dir)
else:
command.append(info)

os.chdir(working_dir)
command.extend(unknown_args)
environment = os.environ.copy()
environment.update(envvars)
Expand All @@ -134,9 +154,6 @@ def launch(arguments, unknown_args):
environment.update({"LD_LIBRARY_PATH": ":".join(splitted)})

print("Launch command:", command)
# Handle case sensitive file systems
if not os.path.exists(working_dir):
working_dir = get_case_insensitive_name(working_dir)

status = None
if sys.platform == 'linux':
Expand All @@ -147,7 +164,7 @@ def launch(arguments, unknown_args):
if result == -1:
print("PR_SET_CHILD_SUBREAPER is not supported by your kernel (Linux 3.4 and above)")

process = subprocess.Popen(command, cwd=working_dir, env=environment)
process = subprocess.Popen(command, env=environment)
process_pid = process.pid

def iterate_processes():
Expand Down Expand Up @@ -213,7 +230,7 @@ def reap_children():


else:
process = subprocess.Popen(command, cwd=working_dir, env=environment,
process = subprocess.Popen(command, env=environment,
shell=sys.platform=="win32")
status = process.wait()

Expand Down

0 comments on commit 151f05f

Please sign in to comment.