mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-10 18:58:19 +00:00
add internal method to emit socket events synchronously, and use it for all exit, quit and relaunch methods
This commit is contained in:
@@ -556,7 +556,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public void Quit()
|
||||
{
|
||||
BridgeConnector.Emit("appQuit");
|
||||
BridgeConnector.EmitSync("appQuit");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -566,7 +566,7 @@ namespace ElectronNET.API
|
||||
/// <param name="exitCode">Exits immediately with exitCode. exitCode defaults to 0.</param>
|
||||
public void Exit(int exitCode = 0)
|
||||
{
|
||||
BridgeConnector.Emit("appExit", exitCode);
|
||||
BridgeConnector.EmitSync("appExit", exitCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -581,7 +581,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public void Relaunch()
|
||||
{
|
||||
BridgeConnector.Emit("appRelaunch");
|
||||
BridgeConnector.EmitSync("appRelaunch");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -599,7 +599,7 @@ namespace ElectronNET.API
|
||||
/// <param name="relaunchOptions">Options for the relaunch.</param>
|
||||
public void Relaunch(RelaunchOptions relaunchOptions)
|
||||
{
|
||||
BridgeConnector.Emit("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
|
||||
BridgeConnector.EmitSync("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -698,8 +698,7 @@ namespace ElectronNET.API
|
||||
|
||||
BridgeConnector.Emit("appGetPath", pathName.GetDescription());
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -539,7 +539,7 @@ namespace ElectronNET.API
|
||||
/// <param name="isForceRunAfter">Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.</param>
|
||||
public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)
|
||||
{
|
||||
BridgeConnector.Emit("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter);
|
||||
BridgeConnector.EmitSync("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -104,6 +104,26 @@ namespace ElectronNET.API
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is only used on places where we need to be sure the event was sent on the socket, such as Quit, Exit, Relaunch and QuitAndInstall methods
|
||||
/// </summary>
|
||||
/// <param name="eventString"></param>
|
||||
/// <param name="args"></param>
|
||||
internal static void EmitSync(string eventString, params object[] args)
|
||||
{
|
||||
if (App.SocketDebug)
|
||||
{
|
||||
Console.WriteLine($"Sending event {eventString}");
|
||||
}
|
||||
|
||||
Socket.EmitAsync(eventString, args).Wait();
|
||||
|
||||
if (App.SocketDebug)
|
||||
{
|
||||
Console.WriteLine($"Sent event {eventString}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Off(string eventString)
|
||||
{
|
||||
Socket.Off(eventString);
|
||||
|
||||
Reference in New Issue
Block a user