Skip to content
Open
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
6 changes: 3 additions & 3 deletions scripts/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using Godot;
using Godot.Collections;
using util;

[GlobalClass]
public partial class SettingsManager : Node
Expand Down Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions scripts/util/Platform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.IO;
using Godot;

namespace util;

public static class Platform
{
/// <summary>
/// Path to the running .app bundle on macOS, the executable lives at Rhythia.app/Contents/MacOS/Rhythia
/// </summary>
public static string MacAppBundlePath => Path.GetFullPath(Path.Combine(OS.GetExecutablePath(), "../../.."));

/// <summary>
/// Wraps a value in single quotes so it is passed to /bin/sh as one literal argument
/// </summary>
public static string ShellQuote(string value) => $"'{value.Replace("'", "'\\''")}'";

/// <summary>
/// Shell snippet that blocks until the current process has exited
/// </summary>
public static string WaitForExitScript => $"while kill -0 {OS.GetProcessId()} 2>/dev/null; do sleep 0.1; done";
}
1 change: 1 addition & 0 deletions scripts/util/Platform.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://d0b88m1ycctvg