Merge pull request #22 from Bananaman/windows_launching
Refactor game launching, and fix Windows support
This commit is contained in:
18
src/game.py
18
src/game.py
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shlex # pylint: disable=unused-import
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -76,12 +77,21 @@ class game(Gtk.Box): # pylint: disable=invalid-name
|
|||||||
self.menu_button.get_popover().connect("notify::visible", self.hide_play)
|
self.menu_button.get_popover().connect("notify::visible", self.hide_play)
|
||||||
|
|
||||||
def launch(self):
|
def launch(self):
|
||||||
# The host environment vars are automatically passed through by Popen.
|
# Generate launch arguments, either list (no shell) or a string (for shell).
|
||||||
subprocess.Popen(
|
args = (
|
||||||
["flatpak-spawn", "--host", *self.executable] # Flatpak
|
["flatpak-spawn", "--host", *self.executable] # Flatpak
|
||||||
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
||||||
else self.executable, # Others
|
else shlex.join(
|
||||||
shell=os.name == "nt", # Set shell to True on Windows
|
self.executable
|
||||||
|
) # Windows (We need shell to support its "open" built-in).
|
||||||
|
if os.name == "nt"
|
||||||
|
else self.executable # Linux/Others
|
||||||
|
)
|
||||||
|
|
||||||
|
# The host environment vars are automatically passed through by Popen.
|
||||||
|
subprocess.Popen(
|
||||||
|
args,
|
||||||
|
shell=isinstance(args, str),
|
||||||
start_new_session=True,
|
start_new_session=True,
|
||||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user