From 14253895d248b6e113c16455d16563935697271c Mon Sep 17 00:00:00 2001 From: Ryan Fraser Date: Wed, 14 Oct 2026 09:54:08 -0500 Subject: [PATCH] fix: restart on macOS and Linux - restartGame passed the relaunch script to /bin/sh without -c, so sh treated it as a filename and the game never came back on macOS/Linux - macOS relaunch resolved Rhythia.app/Contents instead of the .app - Quote paths passed to the shell Co-Authored-By: Claude Opus 5.5 --- scripts/SettingsManager.cs | 6 +++--- scripts/util/Platform.cs | 22 ++++++++++++++++++++++ scripts/util/Platform.cs.uid | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 scripts/util/Platform.cs create mode 100644 scripts/util/Platform.cs.uid diff --git a/scripts/SettingsManager.cs b/scripts/SettingsManager.cs index dc99e357..955d4ab9 100644 --- a/scripts/SettingsManager.cs +++ b/scripts/SettingsManager.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Godot; using Godot.Collections; +using util; [GlobalClass] public partial class SettingsManager : Node @@ -269,11 +270,10 @@ private static void restartGame() OS.CreateProcess("powershell.exe", ["-Command", $"Wait-Process -Id {pid}; Start-Process '{executablePath}'"]); break; case "macOS": - string executablePathMac = Path.Combine(executablePath, "../.."); - OS.CreateProcess("/bin/sh", [$"while kill -0 {pid} 2>/dev/null; do sleep 0.1; done; open {executablePathMac}"]); + OS.CreateProcess("/bin/sh", ["-c", $"{Platform.WaitForExitScript}; open {Platform.ShellQuote(Platform.MacAppBundlePath)}"]); break; case "Linux": - OS.CreateProcess("/bin/sh", [$"while kill -0 {pid} 2>/dev/null; do sleep 0.1; done; exec {executablePath}"]); + OS.CreateProcess("/bin/sh", ["-c", $"{Platform.WaitForExitScript}; exec {Platform.ShellQuote(executablePath)}"]); break; } diff --git a/scripts/util/Platform.cs b/scripts/util/Platform.cs new file mode 100644 index 00000000..593d4669 --- /dev/null +++ b/scripts/util/Platform.cs @@ -0,0 +1,22 @@ +using System.IO; +using Godot; + +namespace util; + +public static class Platform +{ + /// + /// Path to the running .app bundle on macOS, the executable lives at Rhythia.app/Contents/MacOS/Rhythia + /// + public static string MacAppBundlePath => Path.GetFullPath(Path.Combine(OS.GetExecutablePath(), "../../..")); + + /// + /// Wraps a value in single quotes so it is passed to /bin/sh as one literal argument + /// + public static string ShellQuote(string value) => $"'{value.Replace("'", "'\\''")}'"; + + /// + /// Shell snippet that blocks until the current process has exited + /// + public static string WaitForExitScript => $"while kill -0 {OS.GetProcessId()} 2>/dev/null; do sleep 0.1; done"; +} diff --git a/scripts/util/Platform.cs.uid b/scripts/util/Platform.cs.uid new file mode 100644 index 00000000..8124b9d7 --- /dev/null +++ b/scripts/util/Platform.cs.uid @@ -0,0 +1 @@ +uid://d0b88m1ycctvg