misc: chore: Optimize AboutWindowViewModel resource disposal
This commit is contained in:
parent
ad89cf39b6
commit
43f7b000ca
@ -2,6 +2,7 @@ using Avalonia.Media.Imaging;
|
|||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Gommon;
|
||||||
using Ryujinx.Ava.Common;
|
using Ryujinx.Ava.Common;
|
||||||
using Ryujinx.Ava.Common.Locale;
|
using Ryujinx.Ava.Common.Locale;
|
||||||
using Ryujinx.Ava.Utilities.Configuration;
|
using Ryujinx.Ava.Utilities.Configuration;
|
||||||
@ -32,15 +33,16 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||||||
Dispatcher.UIThread.Post(() => UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value));
|
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)
|
private void UpdateLogoTheme(string theme)
|
||||||
{
|
{
|
||||||
bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
|
bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
|
||||||
|
|
||||||
|
string themeName = isDarkTheme ? "Dark" : "Light";
|
||||||
|
|
||||||
string basePath = "resm:Ryujinx.Assets.UIImages.";
|
GithubLogo = LoadBitmap(LogoPathFormat.Format("GitHub", themeName));
|
||||||
string themeSuffix = isDarkTheme ? "Dark.png" : "Light.png";
|
DiscordLogo = LoadBitmap(LogoPathFormat.Format("Discord", themeName));
|
||||||
|
|
||||||
GithubLogo = LoadBitmap($"{basePath}Logo_GitHub_{themeSuffix}?assembly=Ryujinx");
|
|
||||||
DiscordLogo = LoadBitmap($"{basePath}Logo_Discord_{themeSuffix}?assembly=Ryujinx");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap LoadBitmap(string uri) => new(Avalonia.Platform.AssetLoader.Open(new Uri(uri)));
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
|
ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
|
||||||
|
|
||||||
|
GithubLogo.Dispose();
|
||||||
|
DiscordLogo.Dispose();
|
||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@ namespace Ryujinx.Ava.UI.Windows
|
|||||||
{
|
{
|
||||||
public AboutWindow()
|
public AboutWindow()
|
||||||
{
|
{
|
||||||
DataContext = new AboutWindowViewModel();
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
GitHubRepoButton.Tag =
|
GitHubRepoButton.Tag =
|
||||||
@ -28,12 +26,14 @@ namespace Ryujinx.Ava.UI.Windows
|
|||||||
|
|
||||||
public static async Task Show()
|
public static async Task Show()
|
||||||
{
|
{
|
||||||
|
using AboutWindowViewModel viewModel = new();
|
||||||
|
|
||||||
ContentDialog contentDialog = new()
|
ContentDialog contentDialog = new()
|
||||||
{
|
{
|
||||||
PrimaryButtonText = string.Empty,
|
PrimaryButtonText = string.Empty,
|
||||||
SecondaryButtonText = string.Empty,
|
SecondaryButtonText = string.Empty,
|
||||||
CloseButtonText = LocaleManager.Instance[LocaleKeys.UserProfilesClose],
|
CloseButtonText = LocaleManager.Instance[LocaleKeys.UserProfilesClose],
|
||||||
Content = new AboutWindow()
|
Content = new AboutWindow { DataContext = viewModel }
|
||||||
};
|
};
|
||||||
|
|
||||||
Style closeButton = new(x => x.Name("CloseButton"));
|
Style closeButton = new(x => x.Name("CloseButton"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user