From 1c07bf3dd069f2d0855037ea01e4c7dbe1a7027c Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Fri, 1 Nov 2024 15:48:25 -0500 Subject: [PATCH] misc: Abstract repeated logic in markup extensions & move Updater into the base of the Avalonia project. --- src/Ryujinx.Common/Utilities/JsonHelper.cs | 25 +++--------- .../BasicMarkupExtension.cs} | 14 ++----- src/Ryujinx/Common/Markup/MarkupExtensions.cs | 39 +++++++++++++++++++ .../MarkupExtensions/LocaleExtension.cs | 29 -------------- src/Ryujinx/Program.cs | 4 +- .../UI/Controls/ApplicationListView.axaml | 9 +---- .../UI/ViewModels/MainWindowViewModel.cs | 1 - .../UI/Views/Main/MainMenuBarView.axaml.cs | 1 - src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 1 - src/Ryujinx/{Modules/Updater => }/Updater.cs | 3 +- 10 files changed, 52 insertions(+), 74 deletions(-) rename src/Ryujinx/Common/{MarkupExtensions/IconExtension.cs => Markup/BasicMarkupExtension.cs} (60%) create mode 100644 src/Ryujinx/Common/Markup/MarkupExtensions.cs delete mode 100644 src/Ryujinx/Common/MarkupExtensions/LocaleExtension.cs rename src/Ryujinx/{Modules/Updater => }/Updater.cs (99%) diff --git a/src/Ryujinx.Common/Utilities/JsonHelper.cs b/src/Ryujinx.Common/Utilities/JsonHelper.cs index 65b8cb109..276dd5f8c 100644 --- a/src/Ryujinx.Common/Utilities/JsonHelper.cs +++ b/src/Ryujinx.Common/Utilities/JsonHelper.cs @@ -17,29 +17,19 @@ namespace Ryujinx.Common.Utilities /// It is REQUIRED for you to save returned options statically or as a part of static serializer context /// in order to avoid performance issues. You can safely modify returned options for your case before storing. /// - public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true) - { - JsonSerializerOptions options = new() + public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true) => + new() { DictionaryKeyPolicy = _snakeCasePolicy, PropertyNamingPolicy = _snakeCasePolicy, WriteIndented = indented, AllowTrailingCommas = true, - ReadCommentHandling = JsonCommentHandling.Skip, + ReadCommentHandling = JsonCommentHandling.Skip }; - return options; - } + public static string Serialize(T value, JsonTypeInfo typeInfo) => JsonSerializer.Serialize(value, typeInfo); - public static string Serialize(T value, JsonTypeInfo typeInfo) - { - return JsonSerializer.Serialize(value, typeInfo); - } - - public static T Deserialize(string value, JsonTypeInfo typeInfo) - { - return JsonSerializer.Deserialize(value, typeInfo); - } + public static T Deserialize(string value, JsonTypeInfo typeInfo) => JsonSerializer.Deserialize(value, typeInfo); public static void SerializeToFile(string filePath, T value, JsonTypeInfo typeInfo) { @@ -53,10 +43,7 @@ namespace Ryujinx.Common.Utilities return JsonSerializer.Deserialize(file, typeInfo); } - public static void SerializeToStream(Stream stream, T value, JsonTypeInfo typeInfo) - { - JsonSerializer.Serialize(stream, value, typeInfo); - } + public static void SerializeToStream(Stream stream, T value, JsonTypeInfo typeInfo) => JsonSerializer.Serialize(stream, value, typeInfo); private class SnakeCaseNamingPolicy : JsonNamingPolicy { diff --git a/src/Ryujinx/Common/MarkupExtensions/IconExtension.cs b/src/Ryujinx/Common/Markup/BasicMarkupExtension.cs similarity index 60% rename from src/Ryujinx/Common/MarkupExtensions/IconExtension.cs rename to src/Ryujinx/Common/Markup/BasicMarkupExtension.cs index 15b1ad112..73b298bc7 100644 --- a/src/Ryujinx/Common/MarkupExtensions/IconExtension.cs +++ b/src/Ryujinx/Common/Markup/BasicMarkupExtension.cs @@ -1,4 +1,4 @@ -using Avalonia.Data.Core; +using Avalonia.Data.Core; using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml.MarkupExtensions; using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings; @@ -6,16 +6,10 @@ using System; namespace Ryujinx.Ava.Common.Markup { - internal class IconExtension(string iconString) : MarkupExtension + internal abstract class BasicMarkupExtension : MarkupExtension { - private ClrPropertyInfo PropertyInfo - => new( - "Item", - _ => new Projektanker.Icons.Avalonia.Icon { Value = iconString }, - null, - typeof(Projektanker.Icons.Avalonia.Icon) - ); - + protected abstract ClrPropertyInfo PropertyInfo { get; } + public override object ProvideValue(IServiceProvider serviceProvider) => new CompiledBindingExtension( new CompiledBindingPathBuilder() diff --git a/src/Ryujinx/Common/Markup/MarkupExtensions.cs b/src/Ryujinx/Common/Markup/MarkupExtensions.cs new file mode 100644 index 000000000..2af68b606 --- /dev/null +++ b/src/Ryujinx/Common/Markup/MarkupExtensions.cs @@ -0,0 +1,39 @@ +using Avalonia.Data.Core; +using Projektanker.Icons.Avalonia; +using Ryujinx.Ava.Common.Locale; + +namespace Ryujinx.Ava.Common.Markup +{ + internal class IconExtension(string iconString) : BasicMarkupExtension + { + protected override ClrPropertyInfo PropertyInfo + => new( + "Item", + _ => new Icon { Value = iconString }, + null, + typeof(Icon) + ); + } + + internal class SpinningIconExtension(string iconString) : BasicMarkupExtension + { + protected override ClrPropertyInfo PropertyInfo + => new( + "Item", + _ => new Icon { Value = iconString, Animation = IconAnimation.Spin }, + null, + typeof(Icon) + ); + } + + internal class LocaleExtension(LocaleKeys key) : BasicMarkupExtension + { + protected override ClrPropertyInfo PropertyInfo + => new( + "Item", + _ => LocaleManager.Instance[key], + null, + typeof(string) + ); + } +} diff --git a/src/Ryujinx/Common/MarkupExtensions/LocaleExtension.cs b/src/Ryujinx/Common/MarkupExtensions/LocaleExtension.cs deleted file mode 100644 index 60d435e30..000000000 --- a/src/Ryujinx/Common/MarkupExtensions/LocaleExtension.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Avalonia.Data.Core; -using Avalonia.Markup.Xaml; -using Avalonia.Markup.Xaml.MarkupExtensions; -using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings; -using Ryujinx.Ava.Common.Locale; -using System; - -namespace Ryujinx.Ava.Common.Markup -{ - internal class LocaleExtension(LocaleKeys key) : MarkupExtension - { - private ClrPropertyInfo PropertyInfo - => new( - "Item", - _ => LocaleManager.Instance[key], - null, - typeof(string) - ); - - public override object ProvideValue(IServiceProvider serviceProvider) => - new CompiledBindingExtension( - new CompiledBindingPathBuilder() - .Property(PropertyInfo, PropertyInfoAccessorFactory.CreateInpcPropertyAccessor) - .Build() - ) - { Source = LocaleManager.Instance } - .ProvideValue(serviceProvider); - } -} diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 5087d5d82..a6a616c6a 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -14,7 +14,6 @@ using Ryujinx.Common.GraphicsDriver; using Ryujinx.Common.Logging; using Ryujinx.Common.SystemInterop; using Ryujinx.Graphics.Vulkan.MoltenVK; -using Ryujinx.Modules; using Ryujinx.SDL2.Common; using Ryujinx.UI.App.Common; using Ryujinx.UI.Common; @@ -46,8 +45,7 @@ namespace Ryujinx.Ava public static int Main(string[] args) { Version = ReleaseInformation.Version; - - + if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134)) { _ = MessageBoxA(nint.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 1803 and newer.\n", $"Ryujinx {Version}", MbIconwarning); diff --git a/src/Ryujinx/UI/Controls/ApplicationListView.axaml b/src/Ryujinx/UI/Controls/ApplicationListView.axaml index 6c7a080d1..ea748a3bf 100644 --- a/src/Ryujinx/UI/Controls/ApplicationListView.axaml +++ b/src/Ryujinx/UI/Controls/ApplicationListView.axaml @@ -55,14 +55,7 @@ VerticalAlignment="Stretch" ClipToBounds="True" CornerRadius="5"> - - - - - - - - +