From 71a22f41822c9439c258d95ba3a0b37d520e0b3b Mon Sep 17 00:00:00 2001 From: Dan Garner Date: Wed, 2 Sep 2020 21:18:09 +0100 Subject: [PATCH] Fix /info endpoint for when geolocation is unknown #160 --- Control/InfoController.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Control/InfoController.cs b/Control/InfoController.cs index fe562e22..b3e17387 100644 --- a/Control/InfoController.cs +++ b/Control/InfoController.cs @@ -37,16 +37,25 @@ public void GetInfo() Response.ContentType = MimeType.Json; using (var writer = HttpContext.OpenResponseText(Encoding.UTF8, true)) { - writer.Write( - JObject.FromObject(new - { - hardwareKey = ApplicationSettings.Default.HardwareKey.ToString(), - displayName = ApplicationSettings.Default.DisplayName, - timeZone = ApplicationSettings.Default.DisplayTimeZone, - latitude = ClientInfo.Instance.CurrentGeoLocation.Latitude, - longitude = ClientInfo.Instance.CurrentGeoLocation.Longitude - }) - .ToString()); + JObject jObject = JObject.FromObject( new + { + hardwareKey = ApplicationSettings.Default.HardwareKey.ToString(), + displayName = ApplicationSettings.Default.DisplayName, + timeZone = ApplicationSettings.Default.DisplayTimeZone + }); + + if (ClientInfo.Instance.CurrentGeoLocation != null && !ClientInfo.Instance.CurrentGeoLocation.IsUnknown) + { + jObject.Add("latitude", ClientInfo.Instance.CurrentGeoLocation.Latitude); + jObject.Add("longitude", ClientInfo.Instance.CurrentGeoLocation.Longitude); + } + else + { + jObject.Add("latitude", null); + jObject.Add("longitude", null); + } + + writer.Write(jObject.ToString()); } } }