Program.cs 2.5 KB

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