Program.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Diagnostics;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Threading;
  6. using Avalonia;
  7. using Avalonia.Dialogs;
  8. using Avalonia.ReactiveUI;
  9. namespace ControlCatalog.NetCore
  10. {
  11. static class Program
  12. {
  13. [STAThread]
  14. static int Main(string[] args)
  15. {
  16. if (args.Contains("--wait-for-attach"))
  17. {
  18. Console.WriteLine("Attach debugger and use 'Set next statement'");
  19. while (true)
  20. {
  21. Thread.Sleep(100);
  22. if (Debugger.IsAttached)
  23. break;
  24. }
  25. }
  26. var builder = BuildAvaloniaApp();
  27. double GetScaling()
  28. {
  29. var idx = Array.IndexOf(args, "--scaling");
  30. if (idx != 0 && args.Length > idx + 1 &&
  31. double.TryParse(args[idx + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out var scaling))
  32. return scaling;
  33. return 1;
  34. }
  35. if (args.Contains("--fbdev"))
  36. {
  37. SilenceConsole();
  38. return builder.StartLinuxFbDev(args, scaling: GetScaling());
  39. }
  40. else if (args.Contains("--drm"))
  41. {
  42. SilenceConsole();
  43. return builder.StartLinuxDrm(args, scaling: GetScaling());
  44. }
  45. else
  46. return builder.StartWithClassicDesktopLifetime(args);
  47. }
  48. /// <summary>
  49. /// This method is needed for IDE previewer infrastructure
  50. /// </summary>
  51. public static AppBuilder BuildAvaloniaApp()
  52. => AppBuilder.Configure<App>()
  53. .UsePlatformDetect()
  54. .With(new X11PlatformOptions
  55. {
  56. EnableMultiTouch = true,
  57. UseDBusMenu = true
  58. })
  59. .With(new Win32PlatformOptions
  60. {
  61. EnableMultitouch = true,
  62. AllowEglInitialization = true
  63. })
  64. .UseSkia()
  65. .UseReactiveUI()
  66. .UseManagedSystemDialogs()
  67. .LogToDebug();
  68. static void SilenceConsole()
  69. {
  70. new Thread(() =>
  71. {
  72. Console.CursorVisible = false;
  73. while (true)
  74. Console.ReadKey(true);
  75. })
  76. { IsBackground = true }.Start();
  77. }
  78. }
  79. }