Skip to content

Commit 22d800d

Browse files
committed
OpenBrowser returns false if it was unsuccessful
1 parent 89c33bc commit 22d800d

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

‎SpotifyAPI.Web.Auth/AuthUtil.cs‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1+
using System;
12
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34

45
namespace SpotifyAPI.Web.Auth
56
{
67
internal static class AuthUtil
78
{
8-
public static void OpenBrowser(string url)
9+
public static bool OpenBrowser(string url)
910
{
10-
#if NETSTANDARD2_0
11-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
12-
{
13-
url = url.Replace("&", "^&");
14-
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
15-
}
16-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
17-
{
18-
Process.Start("xdg-open", url);
19-
}
20-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
11+
try
2112
{
22-
Process.Start("open", url);
23-
}
13+
#if NETSTANDARD2_0
14+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
15+
{
16+
url = url.Replace("&", "^&");
17+
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
18+
}
19+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
20+
{
21+
Process.Start("xdg-open", url);
22+
}
23+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
24+
{
25+
Process.Start("open", url);
26+
}
2427
#else
2528
url = url.Replace("&", "^&");
2629
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
2730
#endif
31+
return true;
32+
}
33+
catch (Exception)
34+
{
35+
return false;
36+
}
2837
}
2938
}
30-
}
39+
}

‎SpotifyAPI.Web/SpotifyWebAPI.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public SpotifyWebAPI(ProxyConfig proxyConfig)
2727
JsonSettings =
2828
new JsonSerializerSettings
2929
{
30-
NullValueHandling = NullValueHandling.Ignore
30+
NullValueHandling = NullValueHandling.Ignore
3131
}
3232
};
3333
}
@@ -83,7 +83,7 @@ public void Dispose()
8383
/// <summary>
8484
/// Error codes that will trigger auto-retry if <see cref="UseAutoRetry"/> is enabled.
8585
/// </summary>
86-
public IEnumerable<int> RetryErrorCodes { get; set; } = new [] { 500, 502, 503 };
86+
public IEnumerable<int> RetryErrorCodes { get; set; } = new[] { 500, 502, 503 };
8787

8888
#endregion Configuration
8989

@@ -2873,7 +2873,7 @@ public T DownloadData<T>(string url) where T : BasicModel
28732873
private int GetTooManyRequests(ResponseInfo info)
28742874
{
28752875
// 429 is "TooManyRequests" value specified in Spotify API
2876-
if (429 != (int) info.StatusCode)
2876+
if (429 != (int)info.StatusCode)
28772877
{
28782878
return -1;
28792879
}
@@ -2938,4 +2938,4 @@ private Task<Tuple<ResponseInfo, T>> DownloadDataAltAsync<T>(string url)
29382938

29392939
#endregion Util
29402940
}
2941-
}
2941+
}

0 commit comments

Comments
 (0)