PlatformInformationViewModel.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Runtime.InteropServices;
  2. using Avalonia;
  3. using Avalonia.Platform;
  4. using MiniMvvm;
  5. namespace ControlCatalog.ViewModels;
  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 (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
  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. }
  45. public string? PlatformInfo { get; }
  46. }