mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-10 18:58:19 +00:00
add debug option
This commit is contained in:
@@ -15,6 +15,11 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public sealed class App
|
||||
{
|
||||
/// <summary>
|
||||
/// Print every message sent to the socket
|
||||
/// </summary>
|
||||
public static bool SocketDebug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when all windows have been closed.
|
||||
/// <para/>
|
||||
|
||||
@@ -10,12 +10,24 @@ namespace ElectronNET.API
|
||||
private static SocketIO _socket;
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
|
||||
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
|
||||
|
||||
Task.Run(() => Socket.EmitAsync(eventString, args));
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Yield();
|
||||
if (App.SocketDebug)
|
||||
{
|
||||
Console.WriteLine($"Sending event {eventString}");
|
||||
}
|
||||
await Socket.EmitAsync(eventString, args);
|
||||
|
||||
if (App.SocketDebug)
|
||||
{
|
||||
Console.WriteLine($"Sent event {eventString}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void Off(string eventString) => Socket.Off(eventString);
|
||||
|
||||
@@ -71,10 +71,10 @@ namespace ElectronNET.API
|
||||
public Task<bool> IsRegisteredAsync(string accelerator)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.On<bool>("globalShortcut-isRegisteredCompleted", (isRegistered) =>
|
||||
|
||||
BridgeConnector.On<bool>("globalShortcut-isRegisteredCompleted" + accelerator.GetHashCode(), (isRegistered) =>
|
||||
{
|
||||
BridgeConnector.Off("globalShortcut-isRegisteredCompleted");
|
||||
BridgeConnector.Off("globalShortcut-isRegisteredCompleted" + accelerator.GetHashCode());
|
||||
|
||||
taskCompletionSource.SetResult(isRegistered);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user