Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
var user_env = settings_manager.get_value(section, env_key, {})
if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty():
env = user_env
var inherit_environment_key := ".".join(["inherit_parent_environment", app._provider_id])
var inherit_environment := settings_manager.get_value(section, inherit_environment_key, true) as bool
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, false) as bool

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

# Set certain environment variables when not inheriting the parent environment
if not inherit_environment:
if not "HOME" in env:
env["HOME"] = OS.get_environment("HOME")
if not "XDG_SESSION_TYPE" in env:
env["XDG_SESSION_TYPE"] = "x11"
if not "XDG_RUNTIME_DIR" in env:
env["XDG_RUNTIME_DIR"] = OS.get_environment("XDG_RUNTIME_DIR")

# Build any environment variables to include in the command
var env_vars := PackedStringArray()
for key in env.keys():
Expand All @@ -277,6 +288,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp:
# Build the launch command to run
var exec := "env"
var command := ["-C", cwd]
if not inherit_environment:
command.push_front("-i")
command.append_array(env_vars)
command.append_array(sandbox)
command.append(cmd)
Expand Down
4 changes: 4 additions & 0 deletions core/ui/common/launch/game_launch_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var provider_id: String
@onready var cwd_input := $%CWDTextInput
@onready var env_input := $%EnvTextInput
@onready var sandbox_toggle := $%UseSandboxToggle as Toggle
@onready var inherit_env_toggle := $%InheritEnvironmentToggle as Toggle


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


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


# Converts the given dictionary into a string representation. E.g. foo=bar
Expand Down
7 changes: 7 additions & 0 deletions core/ui/common/launch/game_launch_settings.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ layout_mode = 2
title = "Environment Variables"
description = "Environment variables to use when launching the game"

[node name="InheritEnvironmentToggle" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_5wp75")]
unique_name_in_owner = true
layout_mode = 2
text = "Inherit Parent Environment"
separator_visible = false
description = "Whether or not environment variables should be inherited from the current session"

[node name="SandboxSettingsLabel" parent="MarginContainer/VBoxContainer" instance=ExtResource("4_m05uu")]
layout_mode = 2
text = "Sandbox Settings"
Expand Down