From 22d800d4877a7b94c936c01a391432df97276e52 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Thu, 26 Mar 2020 18:34:32 +0100 Subject: [PATCH] OpenBrowser returns false if it was unsuccessful --- SpotifyAPI.Web.Auth/AuthUtil.cs | 39 ++++++++++++++++++++------------- SpotifyAPI.Web/SpotifyWebAPI.cs | 8 +++---- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/SpotifyAPI.Web.Auth/AuthUtil.cs b/SpotifyAPI.Web.Auth/AuthUtil.cs index b72d3ead..cea40708 100644 --- a/SpotifyAPI.Web.Auth/AuthUtil.cs +++ b/SpotifyAPI.Web.Auth/AuthUtil.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Runtime.InteropServices; @@ -5,26 +6,34 @@ namespace SpotifyAPI.Web.Auth { internal static class AuthUtil { - public static void OpenBrowser(string url) + public static bool OpenBrowser(string url) { + try + { #if NETSTANDARD2_0 - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - url = url.Replace("&", "^&"); - 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); - } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = url.Replace("&", "^&"); + 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); + } #else url = url.Replace("&", "^&"); Process.Start(new ProcessStartInfo("cmd", $"/c start {url}")); #endif + return true; + } + catch (Exception) + { + return false; + } } } -} \ No newline at end of file +} diff --git a/SpotifyAPI.Web/SpotifyWebAPI.cs b/SpotifyAPI.Web/SpotifyWebAPI.cs index 6cf94ae9..b6574b34 100644 --- a/SpotifyAPI.Web/SpotifyWebAPI.cs +++ b/SpotifyAPI.Web/SpotifyWebAPI.cs @@ -27,7 +27,7 @@ namespace SpotifyAPI.Web JsonSettings = new JsonSerializerSettings { - NullValueHandling = NullValueHandling.Ignore + NullValueHandling = NullValueHandling.Ignore } }; } @@ -83,7 +83,7 @@ namespace SpotifyAPI.Web /// /// Error codes that will trigger auto-retry if is enabled. /// - public IEnumerable RetryErrorCodes { get; set; } = new [] { 500, 502, 503 }; + public IEnumerable RetryErrorCodes { get; set; } = new[] { 500, 502, 503 }; #endregion Configuration @@ -2873,7 +2873,7 @@ namespace SpotifyAPI.Web private int GetTooManyRequests(ResponseInfo info) { // 429 is "TooManyRequests" value specified in Spotify API - if (429 != (int) info.StatusCode) + if (429 != (int)info.StatusCode) { return -1; } @@ -2938,4 +2938,4 @@ namespace SpotifyAPI.Web #endregion Util } -} \ No newline at end of file +}