Skip to content

Commit

Permalink
Improved Utils.OpenToURL further for unix systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirsario committed Jun 20, 2022
1 parent 7ba27bb commit f6b470d
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions patches/tModLoader/Terraria/Utils.TML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ public static BitArray ReceiveBitArray(int BitArrLength, BinaryReader reader) {
// Common Blocks

public static void OpenToURL(string url) {
var startInfo = new ProcessStartInfo(url) {
UseShellExecute = true,
};

// Without this, some browsers, at the very least Firefox, show an error popup.
// Additionally, this may solve issues that may occur when running with administrator priviliges.
// Do not attempt to shorten this, no universal works-everywhere call exists.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
startInfo.Arguments = startInfo.FileName;
startInfo.FileName = "explorer.exe";
// Windows
Process.Start("explorer.exe", $@"""{url}""");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
// MacOS
Process.Start("open", $@"""{url}""");
}
else {
// Linux & FreeBSD
Process.Start("xdg-open", $@"""{url}""");
}

Process.Start(startInfo);
}

public static void ShowFancyErrorMessage(string message, int returnToMenu) {
Expand Down

0 comments on commit f6b470d

Please sign in to comment.