Skip to content

Commit 8da5b76

Browse files
committed
fix(Launcher): add option for inheriting parent environment
1 parent bc26a7b commit 8da5b76

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

core/global/launch_manager.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
251251
var user_env = settings_manager.get_value(section, env_key, {})
252252
if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty():
253253
env = user_env
254+
var inherit_environment_key := ".".join(["inherit_parent_environment", app._provider_id])
255+
var inherit_environment := settings_manager.get_value(section, inherit_environment_key, true) as bool
254256
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
255257
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, false) as bool
256258

@@ -264,6 +266,15 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
264266
# Set the OGUI ID environment variable
265267
env["OGUI_ID"] = app.name
266268

269+
# Set certain environment variables when not inheriting the parent environment
270+
if not inherit_environment:
271+
if not "HOME" in env:
272+
env["HOME"] = OS.get_environment("HOME")
273+
if not "XDG_SESSION_TYPE" in env:
274+
env["XDG_SESSION_TYPE"] = "x11"
275+
if not "XDG_RUNTIME_DIR" in env:
276+
env["XDG_RUNTIME_DIR"] = OS.get_environment("XDG_RUNTIME_DIR")
277+
267278
# Build any environment variables to include in the command
268279
var env_vars := PackedStringArray()
269280
for key in env.keys():
@@ -277,6 +288,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
277288
# Build the launch command to run
278289
var exec := "env"
279290
var command := ["-C", cwd]
291+
if not inherit_environment:
292+
command.push_front("-i")
280293
command.append_array(env_vars)
281294
command.append_array(sandbox)
282295
command.append(cmd)

core/ui/common/launch/game_launch_settings.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var provider_id: String
2020
@onready var cwd_input := $%CWDTextInput
2121
@onready var env_input := $%EnvTextInput
2222
@onready var sandbox_toggle := $%UseSandboxToggle as Toggle
23+
@onready var inherit_env_toggle := $%InheritEnvironmentToggle as Toggle
2324

2425

2526
# Called when the node enters the scene tree for the first time.
@@ -31,6 +32,7 @@ func _ready() -> void:
3132
cwd_input.focus_exited.connect(_on_input_update.bind(cwd_input, "cwd"))
3233
env_input.focus_exited.connect(_on_input_update.bind(env_input, "env", UPDATE.DICT))
3334
sandbox_toggle.toggled.connect(_on_toggle_update.bind(sandbox_toggle, "use_sandboxing"))
35+
inherit_env_toggle.toggled.connect(_on_toggle_update.bind(inherit_env_toggle, "inherit_parent_environment"))
3436

3537

3638
func _on_game_settings_entered(_from: State) -> void:
@@ -98,6 +100,8 @@ func _on_provider_selected(idx: int) -> void:
98100
sandbox_toggle.button_pressed = use_sandboxing
99101
else:
100102
sandbox_toggle.button_pressed = true
103+
var inherit_env := settings_manager.get_value(settings_section, ".".join(["inherit_parent_environment", provider_id]), true) as bool
104+
inherit_env_toggle.button_pressed = inherit_env
101105

102106

103107
# Converts the given dictionary into a string representation. E.g. foo=bar

core/ui/common/launch/game_launch_settings.tscn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ layout_mode = 2
7272
title = "Environment Variables"
7373
description = "Environment variables to use when launching the game"
7474

75+
[node name="InheritEnvironmentToggle" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_5wp75")]
76+
unique_name_in_owner = true
77+
layout_mode = 2
78+
text = "Inherit Parent Environment"
79+
separator_visible = false
80+
description = "Whether or not environment variables should be inherited from the current session"
81+
7582
[node name="SandboxSettingsLabel" parent="MarginContainer/VBoxContainer" instance=ExtResource("4_m05uu")]
7683
layout_mode = 2
7784
text = "Sandbox Settings"

0 commit comments

Comments
 (0)