mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-22 06:54:44 +00:00
Add flag to check if the socket is connected
This commit is contained in:
@@ -95,6 +95,8 @@ namespace ElectronNET.API
|
||||
|
||||
private static Task _waitForConnection => _waitForBeingConnected.Task;
|
||||
|
||||
public static bool IsConnected => _waitForConnection is Task task && task.IsCompletedSuccessfully;
|
||||
|
||||
public static void Emit(string eventString, params object[] args)
|
||||
{
|
||||
//We don't care about waiting for the event to be emitted, so this doesn't need to be async
|
||||
@@ -387,14 +389,14 @@ namespace ElectronNET.API
|
||||
|
||||
socket.OnConnected += (_, __) =>
|
||||
{
|
||||
Log("ElectronNET socket connected on port {0}!", BridgeSettings.SocketPort);
|
||||
_waitForBeingConnected.TrySetResult();
|
||||
Log("ElectronNET socket connected on port {0}!", BridgeSettings.SocketPort);
|
||||
};
|
||||
|
||||
socket.OnReconnectAttempt += (_, __) =>
|
||||
{
|
||||
Log("ElectronNET socket is trying to reconnect on port {0}...", BridgeSettings.SocketPort);
|
||||
_waitForBeingConnected = new();
|
||||
Log("ElectronNET socket is trying to reconnect on port {0}...", BridgeSettings.SocketPort);
|
||||
};
|
||||
|
||||
socket.OnReconnectError += (_, ex) =>
|
||||
@@ -404,8 +406,8 @@ namespace ElectronNET.API
|
||||
|
||||
socket.OnReconnected += (_, __) =>
|
||||
{
|
||||
Log("ElectronNET socket reconnected on port {0}...", BridgeSettings.SocketPort);
|
||||
_waitForBeingConnected.TrySetResult();
|
||||
Log("ElectronNET socket reconnected on port {0}...", BridgeSettings.SocketPort);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConnected => BridgeConnector.IsConnected;
|
||||
|
||||
/// <summary>
|
||||
/// Listens to channel, when a new message arrives listener would be called with
|
||||
/// listener(event, args...).
|
||||
@@ -62,7 +64,6 @@ namespace ElectronNET.API
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Listens to channel, when a new message arrives listener would be called with
|
||||
/// listener(event, args...). This listner will keep the window event sender id
|
||||
|
||||
Reference in New Issue
Block a user