feat: move the "--debug" option from ui to global

and process it manualy
This commit is contained in:
2026-04-01 10:16:41 +03:00
parent bbf233d14c
commit 498a8619ab
2 changed files with 44 additions and 41 deletions
+42 -8
View File
@@ -13,17 +13,12 @@ public partial class Program
DRM
}
private static string[]? _args = null;
private static List<string>? _args = null;
private static readonly RootCommand _rootCommand = new("Run UI application");
private static readonly Option<bool> _fullscreen = new("--fullscreen")
{
Description = "Run in fullscreen mode"
};
private static readonly Option<bool> _debug = new Option<bool>("--debug")
{
Description = "Wait debugger attach on launch",
Hidden = true
};
private static readonly Option<RenderingMode> _renderingMode = new("--rendering-mode")
{
Description = "Rendering mode to use",
@@ -106,11 +101,14 @@ public partial class Program
[STAThread]
public static int Main(string[] args)
{
_args = args;
_args = args.ToList();
#if DEBUG
WaitDebuggerIfNeeded();
#endif
_rootCommand.SetAction(Ui);
_rootCommand.Add(_fullscreen);
_rootCommand.Add(_debug);
_rootCommand.Add(_renderingMode);
_rootCommand.Add(_hideConsole);
@@ -152,4 +150,40 @@ public partial class Program
ShutdownRequested?.Invoke(sender, ea);
ea.Cancel = true;
}
private static void WaitDebuggerIfNeeded()
{
if (System.Diagnostics.Debugger.IsAttached)
return;
if (_args is null || !_args.Contains("--debug"))
return;
_args.Remove("--debug");
bool keepWaiting = true;
void CancelHandle(object? sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
keepWaiting = false;
Console.WriteLine("\nWait cancelled by user.");
Environment.Exit(0);
}
Console.CancelKeyPress += CancelHandle;
Console.WriteLine("Waiting debugger attach (Press Ctrl+C to cancel)");
Console.WriteLine($"Process Id: {Environment.ProcessId}");
Console.WriteLine($"Process Name: {Environment.ProcessPath}");
Console.WriteLine($"Thread Id: {Thread.CurrentThread.ManagedThreadId}");
Console.WriteLine($"Thread Name: {Thread.CurrentThread.Name}");
while (!System.Diagnostics.Debugger.IsAttached && keepWaiting)
Thread.Sleep(100);
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
Console.CancelKeyPress -= CancelHandle;
}
}