PlatformInformationViewModel.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Avalonia;
  2. using Avalonia.Platform;
  3. using MiniMvvm;
  4. namespace ControlCatalog.ViewModels;
  5. #nullable enable
  6. public class PlatformInformationViewModel : ViewModelBase
  7. {
  8. public PlatformInformationViewModel()
  9. {
  10. var runtimeInfo = AvaloniaLocator.Current.GetService<IRuntimePlatform>()?.GetRuntimeInfo();
  11. if (runtimeInfo is { } info)
  12. {
  13. if (info.IsBrowser)
  14. {
  15. if (info.IsDesktop)
  16. {
  17. PlatformInfo = "Platform: Desktop (browser)";
  18. }
  19. else if (info.IsMobile)
  20. {
  21. PlatformInfo = "Platform: Mobile (browser)";
  22. }
  23. else
  24. {
  25. PlatformInfo = "Platform: Unknown (browser) - please report";
  26. }
  27. }
  28. else
  29. {
  30. if (info.IsDesktop)
  31. {
  32. PlatformInfo = "Platform: Desktop (native)";
  33. }
  34. else if (info.IsMobile)
  35. {
  36. PlatformInfo = "Platform: Mobile (native)";
  37. }
  38. else
  39. {
  40. PlatformInfo = "Platform: Unknown (native) - please report";
  41. }
  42. }
  43. }
  44. else
  45. {
  46. }
  47. }
  48. public string PlatformInfo { get; }
  49. }