Prechádzať zdrojové kódy

misc: chore: Optimize AboutWindowViewModel resource disposal

Evan Husted 1 rok pred
rodič
commit
43f7b000ca

+ 11 - 5
src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs

@@ -2,6 +2,7 @@ using Avalonia.Media.Imaging;
 using Avalonia.Styling;
 using Avalonia.Threading;
 using CommunityToolkit.Mvvm.ComponentModel;
+using Gommon;
 using Ryujinx.Ava.Common;
 using Ryujinx.Ava.Common.Locale;
 using Ryujinx.Ava.Utilities.Configuration;
@@ -32,15 +33,16 @@ namespace Ryujinx.Ava.UI.ViewModels
             Dispatcher.UIThread.Post(() => UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value));
         }
 
+        private const string LogoPathFormat = "resm:Ryujinx.Assets.UIImages.Logo_{0}_{1}.png?assembly=Ryujinx";
+
         private void UpdateLogoTheme(string theme)
         {
             bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
+            
+            string themeName = isDarkTheme ? "Dark" : "Light";
 
-            string basePath = "resm:Ryujinx.Assets.UIImages.";
-            string themeSuffix = isDarkTheme ? "Dark.png" : "Light.png";
-
-            GithubLogo = LoadBitmap($"{basePath}Logo_GitHub_{themeSuffix}?assembly=Ryujinx");
-            DiscordLogo = LoadBitmap($"{basePath}Logo_Discord_{themeSuffix}?assembly=Ryujinx");
+            GithubLogo = LoadBitmap(LogoPathFormat.Format("GitHub", themeName));
+            DiscordLogo = LoadBitmap(LogoPathFormat.Format("Discord", themeName));
         }
 
         private static Bitmap LoadBitmap(string uri) => new(Avalonia.Platform.AssetLoader.Open(new Uri(uri)));
@@ -48,6 +50,10 @@ namespace Ryujinx.Ava.UI.ViewModels
         public void Dispose()
         {
             ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
+            
+            GithubLogo.Dispose();
+            DiscordLogo.Dispose();
+            
             GC.SuppressFinalize(this);
         }
     }

+ 3 - 3
src/Ryujinx/UI/Windows/AboutWindow.axaml.cs

@@ -18,8 +18,6 @@ namespace Ryujinx.Ava.UI.Windows
     {
         public AboutWindow()
         {
-            DataContext = new AboutWindowViewModel();
-
             InitializeComponent();
 
             GitHubRepoButton.Tag =
@@ -28,12 +26,14 @@ namespace Ryujinx.Ava.UI.Windows
 
         public static async Task Show()
         {
+            using AboutWindowViewModel viewModel = new();
+            
             ContentDialog contentDialog = new()
             {
                 PrimaryButtonText = string.Empty,
                 SecondaryButtonText = string.Empty,
                 CloseButtonText = LocaleManager.Instance[LocaleKeys.UserProfilesClose],
-                Content = new AboutWindow()
+                Content = new AboutWindow { DataContext = viewModel }
             };
 
             Style closeButton = new(x => x.Name("CloseButton"));