Skip to content

Commit f190445

Browse files
committed
fix(Launcher): add option for inheriting parent environment
1 parent e3b8023 commit f190445

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
@@ -338,6 +338,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
338338
var user_env = settings_manager.get_value(section, env_key, {})
339339
if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty():
340340
env = user_env
341+
var inherit_environment_key := ".".join(["inherit_parent_environment", app._provider_id])
342+
var inherit_environment := settings_manager.get_value(section, inherit_environment_key, true) as bool
341343
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
342344
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, false) as bool
343345

@@ -351,6 +353,15 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
351353
# Set the OGUI ID environment variable
352354
env["OGUI_ID"] = app.name
353355

356+
# Set certain environment variables when not inheriting the parent environment
357+
if not inherit_environment:
358+
if not "HOME" in env:
359+
env["HOME"] = OS.get_environment("HOME")
360+
if not "XDG_SESSION_TYPE" in env:
361+
env["XDG_SESSION_TYPE"] = "x11"
362+
if not "XDG_RUNTIME_DIR" in env:
363+
env["XDG_RUNTIME_DIR"] = OS.get_environment("XDG_RUNTIME_DIR")
364+
354365
# Build any environment variables to include in the command
355366
var env_vars := PackedStringArray()
356367
for key in env.keys():
@@ -364,6 +375,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
364375
# Build the launch command to run
365376
var exec := "env"
366377
var command := ["-C", cwd]
378+
if not inherit_environment:
379+
command.push_front("-i")
367380
command.append_array(env_vars)
368381
command.append_array(sandbox)
369382
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)