React appropriate to SIGINT (CTRL+C)

We're using custom console mechanism in order to implement interactive console, on top of that CTRL+C would not work when using IPC: true due to the fact that it doesn't trigger shutdown sequence, fix both of those problems by listening to SIGINT and exiting with code 130 upon receiving one

Tested on Linux
This commit is contained in:
Archi
2021-11-01 18:55:58 +01:00
parent a77f0c1ad3
commit 3b5a07aab3

View File

@@ -125,6 +125,8 @@ namespace ArchiSteamFarm {
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
Console.CancelKeyPress += OnCancelKeyPress;
// Add support for custom encodings
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@@ -396,6 +398,8 @@ namespace ArchiSteamFarm {
return await ShutdownResetEvent.Task.ConfigureAwait(false);
}
private static async void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e) => await Exit(130).ConfigureAwait(false);
private static async void OnProcessExit(object? sender, EventArgs e) => await Shutdown().ConfigureAwait(false);
private static async void OnUnhandledException(object? sender, UnhandledExceptionEventArgs e) {