From 592148116bcfc8aa5da2799fa74907f86ccb0d59 Mon Sep 17 00:00:00 2001 From: Todd Schavey Date: Sun, 2 Jan 2022 23:11:01 -0500 Subject: [PATCH] #647 correct to ElectronNET.API Process member for versions field --- ElectronNET.API/BridgeConnector.cs | 33 +++++++++++++++++-- .../{Versions.cs => ProcessVersions.cs} | 4 +-- ElectronNET.API/Process.cs | 4 +-- 3 files changed, 35 insertions(+), 6 deletions(-) rename ElectronNET.API/Entities/{Versions.cs => ProcessVersions.cs} (82%) diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index 3f37e06..8c4d979 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -90,7 +90,22 @@ namespace ElectronNET.API BridgeConnector.Socket.On(eventCompletedString, (value) => { BridgeConnector.Socket.Off(eventCompletedString); - taskCompletionSource.SetResult( ((JObject)value).ToObject() ); + + if (value == null) + { + Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') returned null. Socket loop hang."); + taskCompletionSource.SetCanceled(); + return; + } + + try + { + taskCompletionSource.SetResult( ((JObject)value).ToObject() ); + } + catch (Exception e) + { + Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') exception: {e.Message}. Socket loop hung."); + } }); BridgeConnector.Socket.Emit(eventString); @@ -110,7 +125,21 @@ namespace ElectronNET.API BridgeConnector.Socket.On(eventCompletedString, (value) => { BridgeConnector.Socket.Off(eventCompletedString); - taskCompletionSource.SetResult( ((JArray)value).ToObject() ); + if (value == null) + { + Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') returned null. Socket loop hang."); + taskCompletionSource.SetCanceled(); + return; + } + + try + { + taskCompletionSource.SetResult( ((JArray)value).ToObject() ); + } + catch (Exception e) + { + Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') exception: {e.Message}. Socket loop hung."); + } }); BridgeConnector.Socket.Emit(eventString); diff --git a/ElectronNET.API/Entities/Versions.cs b/ElectronNET.API/Entities/ProcessVersions.cs similarity index 82% rename from ElectronNET.API/Entities/Versions.cs rename to ElectronNET.API/Entities/ProcessVersions.cs index 254a62c..ce61fcb 100644 --- a/ElectronNET.API/Entities/Versions.cs +++ b/ElectronNET.API/Entities/ProcessVersions.cs @@ -3,7 +3,7 @@ namespace ElectronNET.API /// /// /// - public class Versions + public class ProcessVersions { /// /// Gets or sets a value representing Chrome's version string. @@ -13,6 +13,6 @@ namespace ElectronNET.API /// /// Gets or sets a value representing Electron's version string. /// - public bool Electron { get; set; } + public string Electron { get; set; } } } \ No newline at end of file diff --git a/ElectronNET.API/Process.cs b/ElectronNET.API/Process.cs index 0976d20..3a25b44 100644 --- a/ElectronNET.API/Process.cs +++ b/ElectronNET.API/Process.cs @@ -82,11 +82,11 @@ namespace ElectronNET.API /// /// /// - public Task VersionsAsync + public Task VersionsAsync { get { - return BridgeConnector.GetValueOverSocketAsync( + return BridgeConnector.GetObjectOverSocketAsync( "process-versions", "process-versions-Completed"); } }