AboutWindowViewModel.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Avalonia.Media.Imaging;
  2. using Avalonia.Styling;
  3. using Avalonia.Threading;
  4. using CommunityToolkit.Mvvm.ComponentModel;
  5. using Gommon;
  6. using Ryujinx.Ava.Common;
  7. using Ryujinx.Ava.Common.Locale;
  8. using Ryujinx.Ava.Utilities.Configuration;
  9. using System;
  10. namespace Ryujinx.Ava.UI.ViewModels
  11. {
  12. public partial class AboutWindowViewModel : BaseModel, IDisposable
  13. {
  14. [ObservableProperty] private Bitmap _githubLogo;
  15. [ObservableProperty] private Bitmap _discordLogo;
  16. [ObservableProperty] private string _version;
  17. public string Developers => "GreemDev";
  18. public string FormerDevelopers => LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.AboutPageDeveloperListMore, "gdkchan, Ac_K, marysaka, rip in peri peri, LDj3SNuD, emmaus, Thealexbarney, GoffyDude, TSRBerry, IsaacMarovitz");
  19. public AboutWindowViewModel()
  20. {
  21. Version = RyujinxApp.FullAppName + "\n" + Program.Version;
  22. UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value);
  23. ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
  24. }
  25. private void ThemeManager_ThemeChanged()
  26. {
  27. Dispatcher.UIThread.Post(() => UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value));
  28. }
  29. private const string LogoPathFormat = "resm:Ryujinx.Assets.UIImages.Logo_{0}_{1}.png?assembly=Ryujinx";
  30. private void UpdateLogoTheme(string theme)
  31. {
  32. bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
  33. string themeName = isDarkTheme ? "Dark" : "Light";
  34. GithubLogo = LoadBitmap(LogoPathFormat.Format("GitHub", themeName));
  35. DiscordLogo = LoadBitmap(LogoPathFormat.Format("Discord", themeName));
  36. }
  37. private static Bitmap LoadBitmap(string uri) => new(Avalonia.Platform.AssetLoader.Open(new Uri(uri)));
  38. public void Dispose()
  39. {
  40. ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
  41. GithubLogo.Dispose();
  42. DiscordLogo.Dispose();
  43. GC.SuppressFinalize(this);
  44. }
  45. }
  46. }