misc: chore: add/remove event handler as window is opened/closed

This commit is contained in:
Evan Husted 2025-03-05 23:01:37 -06:00
parent 25cc9b24b4
commit 551d2c1134
2 changed files with 25 additions and 8 deletions

View File

@ -1,14 +1,15 @@
using Gommon;
using Ryujinx.Ava.Systems;
using Ryujinx.Ava.Systems.AppLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Ryujinx.Ava.UI.ViewModels
{
public class CompatibilityViewModel : BaseModel
public class CompatibilityViewModel : BaseModel, IDisposable
{
private bool _onlyShowOwnedGames = true;
private readonly ApplicationLibrary _appLibrary;
private IEnumerable<CompatibilityEntry> _currentEntries = CompatibilityDatabase.Entries;
private string[] _ownedGameTitleIds = [];
@ -19,15 +20,27 @@ namespace Ryujinx.Ava.UI.ViewModels
: _currentEntries;
public CompatibilityViewModel() {}
private void AppCountUpdated(object _, ApplicationCountUpdatedEventArgs __)
=> _ownedGameTitleIds = _appLibrary.Applications.Keys.Select(x => x.ToString("X16")).ToArray();
public CompatibilityViewModel(ApplicationLibrary appLibrary)
{
appLibrary.ApplicationCountUpdated += (_, _)
=> _ownedGameTitleIds = appLibrary.Applications.Keys.Select(x => x.ToString("X16")).ToArray();
_appLibrary = appLibrary;
_ownedGameTitleIds = appLibrary.Applications.Keys.Select(x => x.ToString("X16")).ToArray();
AppCountUpdated(null, null);
_appLibrary.ApplicationCountUpdated += AppCountUpdated;
}
void IDisposable.Dispose()
{
GC.SuppressFinalize(this);
_appLibrary.ApplicationCountUpdated -= AppCountUpdated;
}
private bool _onlyShowOwnedGames = true;
public bool OnlyShowOwnedGames
{
get => _onlyShowOwnedGames;

View File

@ -8,13 +8,17 @@ namespace Ryujinx.Ava.UI.Windows
{
public partial class CompatibilityListWindow : StyleableAppWindow
{
public static Task Show(string titleId = null) =>
ShowAsync(new CompatibilityListWindow
public static async Task Show(string titleId = null)
{
using CompatibilityViewModel compatWindow = new(RyujinxApp.MainWindow.ViewModel.ApplicationLibrary);
await ShowAsync(new CompatibilityListWindow
{
DataContext = new CompatibilityViewModel(RyujinxApp.MainWindow.ViewModel.ApplicationLibrary),
DataContext = compatWindow,
SearchBoxFlush = { Text = titleId ?? string.Empty },
SearchBoxNormal = { Text = titleId ?? string.Empty }
});
}
public CompatibilityListWindow() : base(useCustomTitleBar: true, 37)
{