Skip to content

Commit a86b2ab

Browse files
committed
fix(Full Session): loading menu fixes, launch fixes
1 parent 5f5cedb commit a86b2ab

File tree

16 files changed

+128
-38
lines changed

16 files changed

+128
-38
lines changed

core/global/launch_manager.gd

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ var logger := Log.get_logger("LaunchManager", Log.LEVEL.DEBUG)
6464

6565
# Connect to Gamescope signals
6666
func _init() -> void:
67+
_load_persist_data()
68+
6769
# Get the window ID of OpenGamepadUI
6870
if _xwayland_ogui:
6971
var ogui_windows := _xwayland_ogui.get_windows_for_pid(PID)
@@ -77,6 +79,7 @@ func _init() -> void:
7779
if from == to:
7880
return
7981
logger.info("Window focus changed from " + str(from) + " to: " + str(to))
82+
self.check_running.call_deferred()
8083
_xwayland_primary.focused_window_updated.connect(on_focus_changed)
8184

8285
# When focused app changes, update the current app and gamepad profile
@@ -115,6 +118,7 @@ func _init() -> void:
115118
if from == to:
116119
return
117120
logger.debug("Focusable apps changed from", from, "to", to)
121+
self.check_running.call_deferred()
118122
# If focusable apps has changed and the currently focused app no longer exists,
119123
# remove the manual focus
120124
var baselayer_app := _xwayland_primary.baselayer_app
@@ -123,6 +127,14 @@ func _init() -> void:
123127
_xwayland_primary.remove_baselayer_app()
124128
_xwayland_primary.focusable_apps_updated.connect(on_focusable_apps_changed)
125129

130+
# Listen for signals from the secondary Gamescope XWayland
131+
if _xwayland_game:
132+
# Listen for window created/destroyed events
133+
var on_window_created := func(window_id: int):
134+
logger.debug("Window created:", window_id)
135+
self.check_running.call_deferred()
136+
_xwayland_ogui.window_created.connect(on_window_created)
137+
126138
# Whenever the in-game state is entered, set the gamepad profile
127139
var on_game_state_entered := func(_from: State):
128140
if _current_app:
@@ -152,6 +164,7 @@ func _init() -> void:
152164
in_game_state.state_exited.connect(on_game_state_exited)
153165
set_gamepad_profile("")
154166

167+
155168
# Loads persistent data like recent games launched, etc.
156169
func _load_persist_data():
157170
# Create the data directory if it doesn't exist
@@ -189,20 +202,20 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
189202
# Override any parameters that may be in the user's config for this game
190203
var section := ".".join(["game", app.name.to_lower()])
191204
var cmd_key := ".".join(["command", app._provider_id])
192-
var user_cmd = settings_manager.get_value(section, cmd_key)
193-
if user_cmd and user_cmd is String:
205+
var user_cmd = settings_manager.get_value(section, cmd_key, "")
206+
if user_cmd and user_cmd is String and not (user_cmd as String).is_empty():
194207
cmd = user_cmd
195208
var args_key := ".".join(["args", app._provider_id])
196-
var user_args = settings_manager.get_value(section, args_key)
197-
if user_args and user_args is PackedStringArray:
209+
var user_args = settings_manager.get_value(section, args_key, PackedStringArray())
210+
if user_args and user_args is PackedStringArray and not (user_args as PackedStringArray).is_empty():
198211
args = user_args
199212
var cwd_key := ".".join(["cwd", app._provider_id])
200-
var user_cwd = settings_manager.get_value(section, cwd_key)
201-
if user_cwd and user_cwd is String:
213+
var user_cwd = settings_manager.get_value(section, cwd_key, "")
214+
if user_cwd and user_cwd is String and not (user_cwd as String).is_empty():
202215
cwd = user_cwd
203216
var env_key := ".".join(["env", app._provider_id])
204-
var user_env = settings_manager.get_value(section, env_key)
205-
if user_env and user_env is Dictionary:
217+
var user_env = settings_manager.get_value(section, env_key, {})
218+
if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty():
206219
env = user_env
207220
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
208221
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, true) as bool
@@ -376,8 +389,8 @@ func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
376389
logger.info("Setting target devices to: ", target_devices)
377390
gamepad.set_target_devices(target_devices)
378391

379-
var notify := Notification.new("Using gamepad profile: " + profile.name)
380-
notification_manager.show(notify)
392+
#var notify := Notification.new("Using gamepad profile: " + profile.name)
393+
#notification_manager.show(notify)
381394

382395

383396
## Sets the given running app as the current app

core/global/platform.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ enum PLATFORM {
4444
STEAMOS,
4545
MANJARO,
4646
ARCH_LIKE,
47+
NIXOS,
4748
}
4849

4950
var hardware_manager := load("res://core/systems/hardware/hardware_manager.tres") as HardwareManager
5051

5152
## Detected Operating System information
5253
var os_info := _detect_os()
5354
## The OS platform provider detected
54-
var os: PlatformProvider
55+
var os: OSPlatform
5556
## The hardware platform provider detected
5657
var platform: PlatformProvider
5758
var logger := Log.get_logger("Platform", Log.LEVEL.INFO)
@@ -127,6 +128,8 @@ func _init() -> void:
127128
os = load("res://core/platform/os/chimeraos.tres")
128129
if PLATFORM.MANJARO in flags:
129130
os = load("res://core/platform/os/manjaro.tres")
131+
if PLATFORM.NIXOS in flags:
132+
os = load("res://core/platform/os/nixos.tres")
130133

131134
if os:
132135
for action in os.startup_actions:
@@ -286,6 +289,8 @@ func _read_os() -> Array[PLATFORM]:
286289
flags.append(PLATFORM.MANJARO)
287290
if os_info.id_like == "arch":
288291
flags.append(PLATFORM.ARCH_LIKE)
292+
if os_info.id == "nixos":
293+
flags.append(PLATFORM.NIXOS)
289294

290295
return flags
291296

core/platform/os/nixos.gd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
extends OSPlatform
2+
class_name PlatformNixOS
3+
4+
5+
func _init() -> void:
6+
logger.set_name("PlatformNixOS")
7+
logger.set_level(Log.LEVEL.INFO)
8+
logger.info("Detected NixOS platform")
9+
10+
11+
## NixOS typically cannot execute regular binaries, so downloaded binaries will
12+
## be run with 'steam-run'.
13+
func get_binary_compatibility_cmd(cmd: String, args: PackedStringArray) -> Array[String]:
14+
# Hack for steam plugin running steamcmd on NixOS
15+
var command: Array[String] = []
16+
if not cmd.ends_with("steamcmd.sh"):
17+
return command
18+
19+
command.push_back("steam-run")
20+
command.push_back(cmd)
21+
command.append_array(args)
22+
23+
return command

core/platform/os/nixos.tres

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_resource type="Resource" script_class="PlatformNixOS" load_steps=3 format=3 uid="uid://byxeetkb11b3e"]
2+
3+
[ext_resource type="Script" path="res://core/platform/os/nixos.gd" id="1_h88kc"]
4+
[ext_resource type="Script" path="res://core/platform/actions/platform_action.gd" id="2_tc12v"]
5+
6+
[resource]
7+
script = ExtResource("1_h88kc")
8+
name = ""
9+
startup_actions = Array[ExtResource("2_tc12v")]([])
10+
shutdown_actions = Array[ExtResource("2_tc12v")]([])

core/platform/os/os_platform.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ class_name OSPlatform
44

55
@export_category("Images")
66
@export var logo: Texture2D ## Logo of the OS
7+
8+
9+
## If the OS requires running regular binaries through a compatibility tool,
10+
## this method should return the given command/args prepended with the compatibility
11+
## tool to use.
12+
func get_binary_compatibility_cmd(cmd: String, args: PackedStringArray) -> Array[String]:
13+
var result: Array[String] = []
14+
return result

core/systems/debug/log_manager.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,3 @@ func get_available_loggers() -> PackedStringArray:
8888
var logger_names := loggers_by_name.keys()
8989
mutex.unlock()
9090
return logger_names
91-

core/systems/input/input_plumber.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func _init() -> void:
2323
var file := FileAccess.open(DEFAULT_PROFILE, FileAccess.READ)
2424
var content := file.get_as_text()
2525
file.close()
26+
if DirAccess.make_dir_recursive_absolute(PROFILES_DIR) != OK:
27+
var logger := Log.get_logger("InputPlumber", Log.LEVEL.DEBUG)
28+
logger.error("Failed to create gamepad profiles directory")
2629
var new_file := FileAccess.open(DEFAULT_GLOBAL_PROFILE, FileAccess.WRITE)
2730
new_file.store_string(content)
2831
new_file.close()

core/systems/launcher/interactive_process.gd

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ var pty: Pty
1111
var cmd: String
1212
var args: PackedStringArray = []
1313
var pid: int
14+
var platform := load("res://core/global/platform.tres") as Platform
1415
var registry := load("res://core/systems/resource/resource_registry.tres") as ResourceRegistry
1516
var lines_mutex := Mutex.new()
1617
var lines_buffer := PackedStringArray()
1718
var logger := Log.get_logger("InteractiveProcess", Log.LEVEL.INFO)
1819

1920

2021
func _init(command: String, cmd_args: PackedStringArray = []) -> void:
21-
# Hack for steam plugin running steamcmd on NixOS
22-
#if command.ends_with("steamcmd.sh"):
23-
#cmd = "steam-run"
24-
#args = PackedStringArray([command])
25-
#args.append_array(cmd_args)
26-
#return
22+
# Check to see if this OS requires running the command through a binary
23+
# compatibility tool.
24+
if platform and platform.os:
25+
var compatibility_cmd := platform.os.get_binary_compatibility_cmd(command, cmd_args)
26+
if not compatibility_cmd.is_empty():
27+
logger.debug("Using binary compatibility tool")
28+
self.cmd = compatibility_cmd.pop_front()
29+
self.args = PackedStringArray(compatibility_cmd)
30+
return
2731

2832
self.cmd = command
2933
self.args = cmd_args

core/systems/launcher/launcher.gd

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ func _init() -> void:
1111
launch_manager._load_persist_data()
1212

1313

14-
# TODO: Replace this with dbus signaling. This is super shitty.
15-
func _process(delta) -> void:
16-
launch_manager.check_running()
14+
func _ready() -> void:
15+
var timer := Timer.new()
16+
timer.autostart = true
17+
timer.one_shot = false
18+
timer.wait_time = 1
19+
timer.timeout.connect(launch_manager.check_running)
20+
add_child(timer)

core/systems/launcher/reaper.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static func get_pid_status(pid: int) -> Dictionary:
147147
var status_file: FileAccess = FileAccess.open(status_path, FileAccess.READ)
148148
if not status_file:
149149
var logger := Log.get_logger("Reaper")
150-
logger.error("Unable to check status for pid: {0}".format([pid]))
150+
logger.debug("Unable to check status for pid: {0}".format([pid]))
151151
return {}
152152

153153
# Parse the status output
@@ -215,7 +215,7 @@ static func is_gamescope_pid(pid: int) -> bool:
215215
var status: Dictionary = get_pid_status(pid)
216216
if not "Name" in status:
217217
var logger := Log.get_logger("Reaper")
218-
logger.error("No name was found in pid status!")
218+
logger.debug("No name was found in pid status!")
219219
return false
220220
if status["Name"] == "gamescope-wl":
221221
return true

0 commit comments

Comments
 (0)