Program.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. GlProfiles = new List<GlVersion>
  61. {
  62. new GlVersion(GlProfileType.OpenGLES, 2, 0)
  63. }
  64. })
  65. .With(new Win32PlatformOptions
  66. {
  67. EnableMultitouch = true,
  68. AllowEglInitialization = true
  69. })
  70. .UseSkia()
  71. .UseReactiveUI()
  72. .UseManagedSystemDialogs();
  73. static void SilenceConsole()
  74. {
  75. new Thread(() =>
  76. {
  77. Console.CursorVisible = false;
  78. while (true)
  79. Console.ReadKey(true);
  80. })
  81. { IsBackground = true }.Start();
  82. }
  83. }
  84. }