Files
ZonyLrcToolsX/src/ZonyLrcTools.Desktop/Helpers/UrlHelper.cs
2024-06-28 15:07:06 +08:00

34 lines
1.1 KiB
C#

using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ZonyLrcTools.Desktop.Helpers;
public static class UrlHelper
{
public static void OpenLink(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
using var process = Process.Start(new ProcessStartInfo
{
FileName = "/bin/sh",
Arguments = $"-c \"xdg-open {url.Replace("\"", "\\\"")}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
});
}
else
{
using var process = Process.Start(new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? url : "open",
Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? url : "",
CreateNoWindow = true,
UseShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
});
}
}
}