fix: Console Input is disabled on Linux when no standard input is attached. (#1809)

This commit is contained in:
Kamron Batman 2024-06-06 21:20:22 -07:00 • committed by GitHub
parent 832bb24f11
commit 1f8ab0e783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 34 deletions

View file

@ -152,30 +152,38 @@ public static class ConsoleInputHandler
private static async void ProcessConsoleInput()
{
var token = Core.ClosingTokenSource.Token;
while (!token.IsCancellationRequested)
while (!Core.Closing)
{
string input;
try
{
var input = Console.ReadLine()?.Trim();
input = Console.ReadLine()?.Trim();
}
catch
{
logger.Warning("Console commands have been disabled due to an error.");
_initialized = false;
return;
}
if (Volatile.Read(ref _expectUserInput))
{
_input = input;
_receivedUserInput.Set();
_endUserInput.WaitOne();
continue;
}
if (Volatile.Read(ref _expectUserInput))
{
_input = input;
_receivedUserInput.Set();
_endUserInput.WaitOne();
continue;
}
if (string.IsNullOrEmpty(input))
{
continue;
}
if (string.IsNullOrEmpty(input))
{
continue;
}
var splitInput = input.Split(' ', 2);
var command = splitInput[0].ToLower();
var splitInput = input.Split(' ', 2);
var command = splitInput[0].ToLower();
try
{
Action<string> action;
lock (_inputCommands)
{
@ -186,7 +194,7 @@ public static class ConsoleInputHandler
}
catch (Exception e)
{
logger.Warning(e, "Failed to process console input");
logger.Error(e, "Failed to execute console command: {Command}", input);
}
}
}

View file

@ -304,8 +304,8 @@ public static class Core
public static void Kill(bool restart = false)
{
_performProcessKill = true;
_restartOnKill = restart;
_performProcessKill = true;
}
public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
@ -338,7 +338,7 @@ public static class Core
ConsoleInputHandler.ReadLine();
}
Kill();
DoKill();
}
}
@ -379,18 +379,16 @@ public static class Core
logger.Information("Restarting");
if (IsWindows)
{
Process.Start("dotnet", ApplicationAssembly.Location);
using var process = Process.Start("dotnet", $"{ApplicationAssembly.Location} {Arguments}");
}
else
{
var process = new Process
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = ApplicationAssembly.Location,
UseShellExecute = true
}
FileName = "dotnet",
Arguments = $"{ApplicationAssembly.Location} {Arguments}",
UseShellExecute = true
};
process.Start();
@ -403,7 +401,7 @@ public static class Core
}
}
Process.Kill();
Environment.Exit(0);
}
private static void HandleClosed()
@ -561,7 +559,7 @@ public static class Core
if (_performProcessKill)
{
DoKill(_restartOnKill);
break;
}
_tickCount = 0;
@ -590,11 +588,10 @@ public static class Core
catch (Exception e)
{
CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
return;
}
finally
{
World.ExitSerializationThreads();
}
DoKill(_restartOnKill);
}
internal static void RequestSnapshot() => _performSnapshot = true;