Program.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.Controls;
  8. using Avalonia.LinuxFramebuffer.Output;
  9. using Avalonia.Skia;
  10. using Avalonia.ReactiveUI;
  11. using Avalonia.Dialogs;
  12. using System.Collections.Generic;
  13. using System.Threading.Tasks;
  14. namespace ControlCatalog.NetCore
  15. {
  16. static class Program
  17. {
  18. static int Main(string[] args)
  19. {
  20. Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA);
  21. if (args.Contains("--wait-for-attach"))
  22. {
  23. Console.WriteLine("Attach debugger and use 'Set next statement'");
  24. while (true)
  25. {
  26. Thread.Sleep(100);
  27. if (Debugger.IsAttached)
  28. break;
  29. }
  30. }
  31. var builder = BuildAvaloniaApp();
  32. double GetScaling()
  33. {
  34. var idx = Array.IndexOf(args, "--scaling");
  35. if (idx != 0 && args.Length > idx + 1 &&
  36. double.TryParse(args[idx + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out var scaling))
  37. return scaling;
  38. return 1;
  39. }
  40. if (args.Contains("--fbdev"))
  41. {
  42. SilenceConsole();
  43. return builder.StartLinuxFbDev(args, scaling: GetScaling());
  44. }
  45. else if (args.Contains("--drm"))
  46. {
  47. SilenceConsole();
  48. return builder.StartLinuxDrm(args, scaling: GetScaling());
  49. }
  50. else
  51. return builder.StartWithClassicDesktopLifetime(args);
  52. }
  53. /// <summary>
  54. /// This method is needed for IDE previewer infrastructure
  55. /// </summary>
  56. public static AppBuilder BuildAvaloniaApp()
  57. => AppBuilder.Configure<App>()
  58. .UsePlatformDetect()
  59. .With(new X11PlatformOptions { EnableMultiTouch = true })
  60. .With(new Win32PlatformOptions
  61. {
  62. EnableMultitouch = true,
  63. AllowEglInitialization = true
  64. })
  65. .UseSkia()
  66. .UseReactiveUI()
  67. .UseManagedSystemDialogs();
  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. }