AboutWindowViewModel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Avalonia;
  2. using Avalonia.Media.Imaging;
  3. using Avalonia.Threading;
  4. using Ryujinx.Ava.Common.Locale;
  5. using Ryujinx.Common.Utilities;
  6. using Ryujinx.Ui.Common.Configuration;
  7. using System;
  8. using System.Net.Http;
  9. using System.Net.NetworkInformation;
  10. using System.Threading.Tasks;
  11. namespace Ryujinx.Ava.UI.ViewModels
  12. {
  13. public class AboutWindowViewModel : BaseModel
  14. {
  15. private Bitmap _githubLogo;
  16. private Bitmap _discordLogo;
  17. private Bitmap _patreonLogo;
  18. private Bitmap _twitterLogo;
  19. private string _version;
  20. private string _supporters;
  21. public Bitmap GithubLogo
  22. {
  23. get => _githubLogo;
  24. set
  25. {
  26. _githubLogo = value;
  27. OnPropertyChanged();
  28. }
  29. }
  30. public Bitmap DiscordLogo
  31. {
  32. get => _discordLogo;
  33. set
  34. {
  35. _discordLogo = value;
  36. OnPropertyChanged();
  37. }
  38. }
  39. public Bitmap PatreonLogo
  40. {
  41. get => _patreonLogo;
  42. set
  43. {
  44. _patreonLogo = value;
  45. OnPropertyChanged();
  46. }
  47. }
  48. public Bitmap TwitterLogo
  49. {
  50. get => _twitterLogo;
  51. set
  52. {
  53. _twitterLogo = value;
  54. OnPropertyChanged();
  55. }
  56. }
  57. public string Supporters
  58. {
  59. get => _supporters;
  60. set
  61. {
  62. _supporters = value;
  63. OnPropertyChanged();
  64. }
  65. }
  66. public string Version
  67. {
  68. get => _version;
  69. set
  70. {
  71. _version = value;
  72. OnPropertyChanged();
  73. }
  74. }
  75. public string Developers
  76. {
  77. get => string.Format(LocaleManager.Instance[LocaleKeys.AboutPageDeveloperListMore], "gdkchan, Ac_K, marysaka, rip in peri peri, LDj3SNuD, emmaus, Thealexbarney, GoffyDude, TSRBerry, IsaacMarovitz");
  78. }
  79. public AboutWindowViewModel()
  80. {
  81. Version = Program.Version;
  82. var assets = AvaloniaLocator.Current.GetService<Avalonia.Platform.IAssetLoader>();
  83. if (ConfigurationState.Instance.Ui.BaseStyle.Value == "Light")
  84. {
  85. GithubLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_GitHub_Light.png?assembly=Ryujinx.Ui.Common")));
  86. DiscordLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Discord_Light.png?assembly=Ryujinx.Ui.Common")));
  87. PatreonLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Patreon_Light.png?assembly=Ryujinx.Ui.Common")));
  88. TwitterLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Twitter_Light.png?assembly=Ryujinx.Ui.Common")));
  89. }
  90. else
  91. {
  92. GithubLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_GitHub_Dark.png?assembly=Ryujinx.Ui.Common")));
  93. DiscordLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Discord_Dark.png?assembly=Ryujinx.Ui.Common")));
  94. PatreonLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Patreon_Dark.png?assembly=Ryujinx.Ui.Common")));
  95. TwitterLogo = new Bitmap(assets.Open(new Uri("resm:Ryujinx.Ui.Common.Resources.Logo_Twitter_Dark.png?assembly=Ryujinx.Ui.Common")));
  96. }
  97. Dispatcher.UIThread.InvokeAsync(DownloadPatronsJson);
  98. }
  99. private async Task DownloadPatronsJson()
  100. {
  101. if (!NetworkInterface.GetIsNetworkAvailable())
  102. {
  103. Supporters = LocaleManager.Instance[LocaleKeys.ConnectionError];
  104. return;
  105. }
  106. HttpClient httpClient = new();
  107. try
  108. {
  109. string patreonJsonString = await httpClient.GetStringAsync("https://patreon.ryujinx.org/");
  110. Supporters = string.Join(", ", JsonHelper.Deserialize<string[]>(patreonJsonString)) + "\n\n";
  111. }
  112. catch
  113. {
  114. Supporters = LocaleManager.Instance[LocaleKeys.ApiError];
  115. }
  116. }
  117. }
  118. }