PlatformInformationViewModel.cs 1.5 KB

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