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 DRM
} }
private static string[]? _args = null; private static List<string>? _args = null;
private static readonly RootCommand _rootCommand = new("Run UI application"); private static readonly RootCommand _rootCommand = new("Run UI application");
private static readonly Option<bool> _fullscreen = new("--fullscreen") private static readonly Option<bool> _fullscreen = new("--fullscreen")
{ {
Description = "Run in fullscreen mode" 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") private static readonly Option<RenderingMode> _renderingMode = new("--rendering-mode")
{ {
Description = "Rendering mode to use", Description = "Rendering mode to use",
@@ -106,11 +101,14 @@ public partial class Program
[STAThread] [STAThread]
public static int Main(string[] args) public static int Main(string[] args)
{ {
_args = args; _args = args.ToList();
#if DEBUG
WaitDebuggerIfNeeded();
#endif
_rootCommand.SetAction(Ui); _rootCommand.SetAction(Ui);
_rootCommand.Add(_fullscreen); _rootCommand.Add(_fullscreen);
_rootCommand.Add(_debug);
_rootCommand.Add(_renderingMode); _rootCommand.Add(_renderingMode);
_rootCommand.Add(_hideConsole); _rootCommand.Add(_hideConsole);
@@ -152,4 +150,40 @@ public partial class Program
ShutdownRequested?.Invoke(sender, ea); ShutdownRequested?.Invoke(sender, ea);
ea.Cancel = true; 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;
}
} }
+2 -33
View File
@@ -24,52 +24,21 @@ public partial class Program
{ {
var builder = BuildAvaloniaApp(); var builder = BuildAvaloniaApp();
var fullscreen = parseResult.GetValue(_fullscreen); var fullscreen = parseResult.GetValue(_fullscreen);
var debug = parseResult.GetValue(_debug);
var renderingMode = parseResult.GetValue(_renderingMode); var renderingMode = parseResult.GetValue(_renderingMode);
var hideConsole = parseResult.GetValue(_hideConsole); var hideConsole = parseResult.GetValue(_hideConsole);
IsFullscreen = fullscreen; IsFullscreen = fullscreen;
#if DEBUG
if (debug && !System.Diagnostics.Debugger.IsAttached)
{
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;
}
#endif
if (hideConsole) if (hideConsole)
SilenceConsole(); SilenceConsole();
switch (renderingMode) switch (renderingMode)
{ {
case RenderingMode.X11: case RenderingMode.X11:
builder.StartWithClassicDesktopLifetime(_args ?? []); builder.StartWithClassicDesktopLifetime(_args?.ToArray() ?? []);
break; break;
case RenderingMode.DRM: case RenderingMode.DRM:
builder.StartLinuxDrm(_args ?? [], "/dev/dri/card1", 1.0); builder.StartLinuxDrm(_args?.ToArray() ?? [], "/dev/dri/card1", 1.0);
break; break;
} }
} }