Browse Source

pass all env vars to engine

Fabian Peter Hammerle 4 years ago
parent
commit
e8f594db8b
2 changed files with 16 additions and 15 deletions
  1. 2 0
      CHANGELOG.md
  2. 14 15
      tooncher/__init__.py

+ 2 - 0
CHANGELOG.md

@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
     - `tooncher.login`
   - `start_engine` & `launch`: expected `isinstance(engine_path, pathlib.Path)`
     (instead of `str`)
+- pass all env vars to engine
+  (e.g., enables use of `optirun tooncher …`)
 
 ### Removed
 - python interface:

+ 14 - 15
tooncher/__init__.py

@@ -1,3 +1,4 @@
+import copy
 import datetime
 import json
 import os
@@ -19,25 +20,23 @@ _LOGIN_API_URL = "https://www.toontownrewritten.com/api/login?format=json"
 def start_engine(
     engine_path: pathlib.Path, gameserver: str, playcookie: str, **popen_kwargs
 ) -> subprocess.Popen:
-    env = {
-        "TTR_GAMESERVER": gameserver,
-        "TTR_PLAYCOOKIE": playcookie,
-    }
+    # without XAUTHORITY:
+    # > :display:x11display(error): Could not open display ":0.0".
+    # > :ToonBase: Default graphics pipe is glxGraphicsPipe (OpenGL).
+    # > :ToonBase(warning): Unable to open 'onscreen' window.
+    # > Traceback (most recent call last):
+    # >   File "<compiled '__voltorbmain__'>", line 0, in <module>
+    # >   [...]
+    # >   File "<compiled 'direct.vlt8f63e471.ShowBase'>", line 0, in vltf05fd21b
+    # > Exception: Could not open window.
+    # optirun sets plenty of env vars
+    env = copy.copy(os.environ)
+    env["TTR_GAMESERVER"] = gameserver
+    env["TTR_PLAYCOOKIE"] = playcookie
     engine_path = engine_path.resolve()
     if sys.platform == "darwin":
         env["DYLD_LIBRARY_PATH"] = str(engine_path.parent.joinpath("Libraries.bundle"))
         env["DYLD_FRAMEWORK_PATH"] = str(engine_path.parent.joinpath("Frameworks"))
-    elif sys.platform == "linux" and "XAUTHORITY" in os.environ:
-        # Fix for TTREngine reporting:
-        # > :display:x11display(error): Could not open display ":0.0".
-        # > :ToonBase: Default graphics pipe is glxGraphicsPipe (OpenGL).
-        # > :ToonBase(warning): Unable to open 'onscreen' window.
-        # > Traceback (most recent call last):
-        # >   File "<compiled '__voltorbmain__'>", line 0, in <module>
-        # >   [...]
-        # >   File "<compiled 'direct.vlt8f63e471.ShowBase'>", line 0, in vltf05fd21b
-        # > Exception: Could not open window.
-        env["XAUTHORITY"] = os.environ["XAUTHORITY"]
     return subprocess.Popen(
         args=[str(engine_path)], cwd=engine_path.parent, env=env, **popen_kwargs,
     )