diff --git a/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs b/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs index fedd90ee2..dc99de2b6 100644 --- a/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs +++ b/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs @@ -3,7 +3,7 @@ using System.Numerics; namespace Ryujinx.Graphics.Texture.Astc { - internal struct IntegerEncoded + internal struct IntegerEncoded(IntegerEncoded.EIntegerEncoding encoding, int numBits) { internal const int StructSize = 8; private static readonly IntegerEncoded[] _encodings; @@ -15,11 +15,11 @@ namespace Ryujinx.Graphics.Texture.Astc Trit, } - readonly EIntegerEncoding _encoding; - public byte NumberBits { get; private set; } - public byte TritValue { get; private set; } - public byte QuintValue { get; private set; } - public int BitValue { get; private set; } + readonly EIntegerEncoding _encoding = encoding; + public byte NumberBits { get; } = (byte)numBits; + public byte TritValue { get; private set; } = 0; + public byte QuintValue { get; private set; } = 0; + public int BitValue { get; private set; } = 0; static IntegerEncoded() { @@ -31,15 +31,6 @@ namespace Ryujinx.Graphics.Texture.Astc } } - public IntegerEncoded(EIntegerEncoding encoding, int numBits) - { - _encoding = encoding; - NumberBits = (byte)numBits; - BitValue = 0; - TritValue = 0; - QuintValue = 0; - } - public readonly bool MatchesEncoding(IntegerEncoded other) { return _encoding == other._encoding && NumberBits == other.NumberBits; diff --git a/src/Ryujinx.HLE/HOS/Applets/IApplet.cs b/src/Ryujinx.HLE/HOS/Applets/IApplet.cs index 985887c47..bc5353841 100644 --- a/src/Ryujinx.HLE/HOS/Applets/IApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/IApplet.cs @@ -15,14 +15,8 @@ namespace Ryujinx.HLE.HOS.Applets ResultCode GetResult(); - bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) - { - return false; - } + bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false; - static T ReadStruct(ReadOnlySpan data) where T : unmanaged - { - return MemoryMarshal.Cast(data)[0]; - } + static T ReadStruct(ReadOnlySpan data) where T : unmanaged => MemoryMarshal.Cast(data)[0]; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs index 148628136..ffeddbb72 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs @@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib { // NOTE: This call reset two internal fields to 0 and one internal field to "true". // It seems to be used only with software keyboard inline. - // Since we doesn't support applets for now, it's fine to stub it. + // Since we don't support applets for now, it's fine to stub it. Logger.Stub?.PrintStub(LogClass.ServiceAm); diff --git a/src/Ryujinx.Input/HLE/InputManager.cs b/src/Ryujinx.Input/HLE/InputManager.cs index 7111f5502..2825542a0 100644 --- a/src/Ryujinx.Input/HLE/InputManager.cs +++ b/src/Ryujinx.Input/HLE/InputManager.cs @@ -2,18 +2,13 @@ using System; namespace Ryujinx.Input.HLE { - public class InputManager : IDisposable + public class InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver) + : IDisposable { - public IGamepadDriver KeyboardDriver { get; private set; } - public IGamepadDriver GamepadDriver { get; private set; } + public IGamepadDriver KeyboardDriver { get; } = keyboardDriver; + public IGamepadDriver GamepadDriver { get; } = gamepadDriver; public IGamepadDriver MouseDriver { get; private set; } - public InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver) - { - KeyboardDriver = keyboardDriver; - GamepadDriver = gamepadDriver; - } - public void SetMouseDriver(IGamepadDriver mouseDriver) { MouseDriver?.Dispose(); diff --git a/src/Ryujinx/App.axaml.cs b/src/Ryujinx/App.axaml.cs index 465094e9f..66aebbe62 100644 --- a/src/Ryujinx/App.axaml.cs +++ b/src/Ryujinx/App.axaml.cs @@ -4,6 +4,8 @@ using Avalonia.Markup.Xaml; using Avalonia.Platform; using Avalonia.Styling; using Avalonia.Threading; +using FluentAvalonia.UI.Windowing; +using Gommon; using Ryujinx.Ava.Common; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.UI.Helpers; @@ -24,6 +26,15 @@ namespace Ryujinx.Ava ? $"Ryujinx {Program.Version}" : $"Ryujinx {Program.Version} - {LocaleManager.Instance[windowTitleKey.Value]}"; + public static MainWindow MainWindow => Current! + .ApplicationLifetime.Cast() + .MainWindow.Cast(); + + public static void SetTaskbarProgress(TaskBarProgressBarState state) => MainWindow.PlatformFeatures.SetTaskBarProgressBarState(state); + public static void SetTaskbarProgressValue(ulong current, ulong total) => MainWindow.PlatformFeatures.SetTaskBarProgressBarValue(current, total); + public static void SetTaskbarProgressValue(long current, long total) => SetTaskbarProgressValue(Convert.ToUInt64(current), Convert.ToUInt64(total)); + + public override void Initialize() { Name = FormatTitle(); @@ -62,8 +73,7 @@ namespace Ryujinx.Ava private void ShowRestartDialog() { -#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed - Dispatcher.UIThread.InvokeAsync(async () => + _ = Dispatcher.UIThread.InvokeAsync(async () => { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { @@ -82,7 +92,6 @@ namespace Ryujinx.Ava } } }); -#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } private void ThemeChanged_Event(object sender, ReactiveEventArgs e) @@ -134,16 +143,9 @@ namespace Ryujinx.Ava _ => ThemeVariant.Default, }; - public static ThemeVariant DetectSystemTheme() - { - if (Application.Current is App app) - { - var colorValues = app.PlatformSettings.GetColorValues(); - - return ConvertThemeVariant(colorValues.ThemeVariant); - } - - return ThemeVariant.Default; - } + public static ThemeVariant DetectSystemTheme() => + Current is App { PlatformSettings: not null } app + ? ConvertThemeVariant(app.PlatformSettings.GetColorValues().ThemeVariant) + : ThemeVariant.Default; } } diff --git a/src/Ryujinx/Modules/Updater/Updater.cs b/src/Ryujinx/Modules/Updater/Updater.cs index 9f186f2b3..2f0bd8b3b 100644 --- a/src/Ryujinx/Modules/Updater/Updater.cs +++ b/src/Ryujinx/Modules/Updater/Updater.cs @@ -466,7 +466,7 @@ namespace Ryujinx.Modules using Stream updateFileStream = File.Open(updateFile, FileMode.Create); long totalBytes = response.Content.Headers.ContentLength.Value; - long byteWritten = 0; + long bytesWritten = 0; byte[] buffer = new byte[32 * 1024]; @@ -479,9 +479,10 @@ namespace Ryujinx.Modules break; } - byteWritten += readSize; + bytesWritten += readSize; - taskDialog.SetProgressBarState(GetPercentage(byteWritten, totalBytes), TaskDialogProgressState.Normal); + taskDialog.SetProgressBarState(GetPercentage(bytesWritten, totalBytes), TaskDialogProgressState.Normal); + App.SetTaskbarProgressValue(bytesWritten, totalBytes); updateFileStream.Write(buffer, 0, readSize); } diff --git a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs index 4bcf8eb94..6eb9fff8b 100644 --- a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs +++ b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs @@ -198,9 +198,6 @@ namespace Ryujinx.Ava.UI.Applet return showDetails; } - public IDynamicTextInputHandler CreateDynamicTextInputHandler() - { - return new AvaloniaDynamicTextInputHandler(_parent); - } + public IDynamicTextInputHandler CreateDynamicTextInputHandler() => new AvaloniaDynamicTextInputHandler(_parent); } } diff --git a/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs b/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs index 0e7cfb8e6..56be50dce 100644 --- a/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs +++ b/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs @@ -102,14 +102,8 @@ namespace Ryujinx.Ava.UI.Applet public bool TextProcessingEnabled { - get - { - return Volatile.Read(ref _canProcessInput); - } - set - { - Volatile.Write(ref _canProcessInput, value); - } + get => Volatile.Read(ref _canProcessInput); + set => Volatile.Write(ref _canProcessInput, value); } public event DynamicTextChangedHandler TextChangedEvent; @@ -135,23 +129,19 @@ namespace Ryujinx.Ava.UI.Applet }); } - public void SetText(string text, int cursorBegin) - { + public void SetText(string text, int cursorBegin) => Dispatcher.UIThread.Post(() => { _hiddenTextBox.Text = text; _hiddenTextBox.CaretIndex = cursorBegin; }); - } - public void SetText(string text, int cursorBegin, int cursorEnd) - { + public void SetText(string text, int cursorBegin, int cursorEnd) => Dispatcher.UIThread.Post(() => { _hiddenTextBox.Text = text; _hiddenTextBox.SelectionStart = cursorBegin; _hiddenTextBox.SelectionEnd = cursorEnd; }); - } } } diff --git a/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs b/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs index e1634e62a..2caf1f0cb 100644 --- a/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs +++ b/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs @@ -84,7 +84,7 @@ namespace Ryujinx.Ava.UI.Helpers return await ShowContentDialog(title, content, primaryButton, secondaryButton, closeButton, primaryButtonResult, deferResetEvent, deferCloseAction); } - public static Task ShowDeferredContentDialog( + public static async Task ShowDeferredContentDialog( Window window, string title, string primaryText, @@ -98,7 +98,7 @@ namespace Ryujinx.Ava.UI.Helpers { bool startedDeferring = false; - return ShowTextDialog( + return await ShowTextDialog( title, primaryText, secondaryText, @@ -209,14 +209,14 @@ namespace Ryujinx.Ava.UI.Helpers closeButton, (int)Symbol.Important); - internal static Task CreateConfirmationDialog( + internal static async Task CreateConfirmationDialog( string primaryText, string secondaryText, string acceptButtonText, string cancelButtonText, string title, UserResult primaryButtonResult = UserResult.Yes) - => ShowTextDialog( + => await ShowTextDialog( string.IsNullOrWhiteSpace(title) ? LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle] : title, primaryText, secondaryText, @@ -226,16 +226,16 @@ namespace Ryujinx.Ava.UI.Helpers (int)Symbol.Help, primaryButtonResult); - internal static Task CreateLocalizedConfirmationDialog(string primaryText, string secondaryText) - => CreateConfirmationDialog( + internal static async Task CreateLocalizedConfirmationDialog(string primaryText, string secondaryText) + => await CreateConfirmationDialog( primaryText, secondaryText, LocaleManager.Instance[LocaleKeys.InputDialogYes], LocaleManager.Instance[LocaleKeys.InputDialogNo], LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); - internal static Task CreateUpdaterInfoDialog(string primary, string secondaryText) - => ShowTextDialog( + internal static async Task CreateUpdaterInfoDialog(string primary, string secondaryText) + => await ShowTextDialog( LocaleManager.Instance[LocaleKeys.DialogUpdaterTitle], primary, secondaryText, @@ -244,8 +244,8 @@ namespace Ryujinx.Ava.UI.Helpers LocaleManager.Instance[LocaleKeys.InputDialogOk], (int)Symbol.Important); - internal static Task CreateWarningDialog(string primary, string secondaryText) - => ShowTextDialog( + internal static async Task CreateWarningDialog(string primary, string secondaryText) + => await ShowTextDialog( LocaleManager.Instance[LocaleKeys.DialogWarningTitle], primary, secondaryText, @@ -254,11 +254,11 @@ namespace Ryujinx.Ava.UI.Helpers LocaleManager.Instance[LocaleKeys.InputDialogOk], (int)Symbol.Important); - internal static Task CreateErrorDialog(string errorMessage, string secondaryErrorMessage = "") + internal static async Task CreateErrorDialog(string errorMessage, string secondaryErrorMessage = "") { Logger.Error?.Print(LogClass.Application, errorMessage); - return ShowTextDialog( + await ShowTextDialog( LocaleManager.Instance[LocaleKeys.DialogErrorTitle], LocaleManager.Instance[LocaleKeys.DialogErrorMessage], errorMessage, @@ -399,11 +399,9 @@ namespace Ryujinx.Ava.UI.Helpers return result; } - public static Task ShowWindowAsync(Window dialogWindow, Window mainWindow = null) + public static async Task ShowWindowAsync(Window dialogWindow, Window mainWindow = null) { - mainWindow ??= GetMainWindow(); - - return dialogWindow.ShowDialog(_contentDialogOverlayWindow ?? mainWindow); + await dialogWindow.ShowDialog(_contentDialogOverlayWindow ?? mainWindow ?? GetMainWindow()); } private static Window GetMainWindow()