From 20e0dbe97f1fdd946e86d380383c45c7c8964b9d Mon Sep 17 00:00:00 2001 From: Jimmy Reichley Date: Sun, 18 Aug 2024 16:37:18 -0400 Subject: [PATCH] Remove dead code; bind to AppLibrary apps directly in mainwindow --- .../App/ApplicationLibrary.cs | 15 +-------- .../App/DownloadableContentAddedEventArgs.cs | 10 ------ .../App/TitleUpdateAddedEventArgs.cs | 10 ------ .../UI/ViewModels/MainWindowViewModel.cs | 9 +++--- .../UI/Views/Main/MainStatusBarView.axaml.cs | 2 +- src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 32 ++++++------------- 6 files changed, 17 insertions(+), 61 deletions(-) delete mode 100644 src/Ryujinx.UI.Common/App/DownloadableContentAddedEventArgs.cs delete mode 100644 src/Ryujinx.UI.Common/App/TitleUpdateAddedEventArgs.cs diff --git a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs index c92ef3b6a..35b9ca185 100644 --- a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs +++ b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs @@ -1,5 +1,4 @@ using DynamicData; -using DynamicData.Kernel; using LibHac; using LibHac.Common; using LibHac.Fs; @@ -24,7 +23,6 @@ using Ryujinx.UI.Common.Helper; using Ryujinx.UI.Common.Models; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Reflection; @@ -44,8 +42,6 @@ namespace Ryujinx.UI.App.Common public Language DesiredLanguage { get; set; } public event EventHandler ApplicationAdded; public event EventHandler ApplicationCountUpdated; - public event EventHandler TitleUpdateAdded; - public event EventHandler DownloadableContentAdded; public IObservableCache Applications; public IObservableCache<(TitleUpdateModel TitleUpdate, bool IsSelected), TitleUpdateModel> TitleUpdates; @@ -553,6 +549,7 @@ namespace Ryujinx.UI.App.Common { Logger.Warning?.Print(LogClass.Application, $"The file encountered was not of a valid type. File: '{filePath}' Error: {exception}"); } + return false; } @@ -1056,16 +1053,6 @@ namespace Ryujinx.UI.App.Common ApplicationCountUpdated?.Invoke(null, e); } - protected void OnTitleUpdateAdded(TitleUpdateAddedEventArgs e) - { - TitleUpdateAdded?.Invoke(null, e); - } - - protected void OnDownloadableContentAdded(DownloadableContentAddedEventArgs e) - { - DownloadableContentAdded?.Invoke(null, e); - } - public static ApplicationMetadata LoadAndSaveMetaData(string titleId, Action modifyFunction = null) { string metadataFolder = Path.Combine(AppDataManager.GamesDirPath, titleId, "gui"); diff --git a/src/Ryujinx.UI.Common/App/DownloadableContentAddedEventArgs.cs b/src/Ryujinx.UI.Common/App/DownloadableContentAddedEventArgs.cs deleted file mode 100644 index f81caa62b..000000000 --- a/src/Ryujinx.UI.Common/App/DownloadableContentAddedEventArgs.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Ryujinx.UI.Common.Models; -using System; - -namespace Ryujinx.UI.App.Common -{ - public class DownloadableContentAddedEventArgs : EventArgs - { - public DownloadableContentModel DownloadableContent { get; set; } - } -} diff --git a/src/Ryujinx.UI.Common/App/TitleUpdateAddedEventArgs.cs b/src/Ryujinx.UI.Common/App/TitleUpdateAddedEventArgs.cs deleted file mode 100644 index bb266d639..000000000 --- a/src/Ryujinx.UI.Common/App/TitleUpdateAddedEventArgs.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Ryujinx.UI.Common.Models; -using System; - -namespace Ryujinx.UI.App.Common -{ - public class TitleUpdateAddedEventArgs : EventArgs - { - public TitleUpdateModel TitleUpdate { get; set; } - } -} diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index bd9f165b9..a61978155 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -6,6 +6,7 @@ using Avalonia.Media; using Avalonia.Platform.Storage; using Avalonia.Threading; using DynamicData; +using DynamicData.Alias; using DynamicData.Binding; using LibHac.Common; using Ryujinx.Ava.Common; @@ -50,7 +51,7 @@ namespace Ryujinx.Ava.UI.ViewModels { private const int HotKeyPressDelayMs = 500; - private ObservableCollection _applications; + private ObservableCollectionExtended _applications; private string _aspectStatusText; private string _loadHeading; @@ -112,8 +113,8 @@ namespace Ryujinx.Ava.UI.ViewModels public MainWindowViewModel() { - Applications = new ObservableCollection(); - + Applications = new ObservableCollectionExtended(); + Applications.ToObservableChangeSet() .Filter(Filter) .Sort(GetComparer()) @@ -741,7 +742,7 @@ namespace Ryujinx.Ava.UI.ViewModels get => FileAssociationHelper.IsTypeAssociationSupported; } - public ObservableCollection Applications + public ObservableCollectionExtended Applications { get => _applications; set diff --git a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs index 528495713..18d0f1a48 100644 --- a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs @@ -53,7 +53,7 @@ namespace Ryujinx.Ava.UI.Views.Main { Window.LoadApplications(); } - + private void VolumeStatus_OnPointerWheelChanged(object sender, PointerWheelEventArgs e) { // Change the volume by 5% at a time diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index 8afa757b8..7947b4896 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -4,6 +4,7 @@ using Avalonia.Controls.Primitives; using Avalonia.Interactivity; using Avalonia.Platform; using Avalonia.Threading; +using DynamicData; using FluentAvalonia.UI.Controls; using LibHac.Tools.FsSystem; using Ryujinx.Ava.Common; @@ -26,6 +27,7 @@ using Ryujinx.UI.Common.Configuration; using Ryujinx.UI.Common.Helper; using System; using System.Collections.Generic; +using System.Reactive.Linq; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -45,6 +47,7 @@ namespace Ryujinx.Ava.UI.Windows private static string _launchApplicationId; private static bool _startFullscreen; internal readonly AvaHostUIHandler UiHandler; + private IDisposable _appLibraryAppsSubscription; public VirtualFileSystem VirtualFileSystem { get; private set; } public ContentManager ContentManager { get; private set; } @@ -136,26 +139,6 @@ namespace Ryujinx.Ava.UI.Windows Program.DesktopScaleFactor = this.RenderScaling; } - private void ApplicationLibrary_ApplicationAdded(object sender, ApplicationAddedEventArgs e) - { - Dispatcher.UIThread.Post(() => - { - ViewModel.Applications.Add(e.AppData); - }); - } - - private void ApplicationLibrary_DownloadableContentAdded(object sender, DownloadableContentAddedEventArgs e) - { - var it = e.DownloadableContent; - Console.WriteLine("[{0}]: {1} ({2})", it.TitleIdBase, it.ContainerPath, it.FullPath); - } - - private void ApplicationLibrary_TitleUpdateAdded(object sender, TitleUpdateAddedEventArgs e) - { - var it = e.TitleUpdate; - Console.WriteLine("[{0}]: {1}", it.TitleIdBase, it.Path); - } - private void ApplicationLibrary_ApplicationCountUpdated(object sender, ApplicationCountUpdatedEventArgs e) { LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.StatusBarGamesLoaded, e.NumAppsLoaded, e.NumAppsFound); @@ -484,7 +467,12 @@ namespace Ryujinx.Ava.UI.Windows this); ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated; - ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded; + _appLibraryAppsSubscription?.Dispose(); + _appLibraryAppsSubscription = ApplicationLibrary.Applications + .Connect() + .ObserveOn(SynchronizationContext.Current) + .Bind(ViewModel.Applications) + .Subscribe(); ViewModel.RefreshFirmwareStatus(); @@ -587,6 +575,7 @@ namespace Ryujinx.Ava.UI.Windows ApplicationLibrary.CancelLoading(); InputManager.Dispose(); + _appLibraryAppsSubscription?.Dispose(); Program.Exit(); base.OnClosing(e); @@ -608,7 +597,6 @@ namespace Ryujinx.Ava.UI.Windows public void LoadApplications() { _applicationsLoadedOnce = true; - ViewModel.Applications.Clear(); StatusBarView.LoadProgressBar.IsVisible = true; ViewModel.StatusBarProgressMaximum = 0;