33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text.Json;
|
|
|
|
namespace Nebula.Shared.Utils;
|
|
|
|
public static class Helper
|
|
{
|
|
public static readonly JsonSerializerOptions JsonWebOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
public static void OpenBrowser(string url)
|
|
{
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
Process.Start("xdg-open", url);
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
{
|
|
Process.Start("open", url);
|
|
}
|
|
}
|
|
|
|
public static async Task<T> AsJson<T>(this HttpContent content) where T : notnull
|
|
{
|
|
var str = await content.ReadAsStringAsync();
|
|
return JsonSerializer.Deserialize<T>(str, JsonWebOptions) ??
|
|
throw new JsonException("AsJson: did not expect null response");
|
|
}
|
|
} |