From 16a60fdf123c54e5f98d887e8ceb5352c3c5b18f Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Tue, 24 Dec 2024 13:39:48 -0600 Subject: [PATCH] UI: Rename App to RyujinxApp Add more NotificationHelper methods Simplify ID copy logic --- src/Ryujinx/Common/ApplicationHelper.cs | 9 ++-- src/Ryujinx/Program.cs | 6 +-- src/Ryujinx/{App.axaml => RyujinxApp.axaml} | 2 +- .../{App.axaml.cs => RyujinxApp.axaml.cs} | 12 +++-- .../UI/Controls/ApplicationListView.axaml.cs | 20 +++++---- src/Ryujinx/UI/Helpers/NotificationHelper.cs | 45 +++++++++++++++++-- .../UI/ViewModels/AboutWindowViewModel.cs | 4 +- .../UI/ViewModels/MainWindowViewModel.cs | 2 +- src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs | 4 +- src/Ryujinx/UI/Windows/CheatWindow.axaml.cs | 4 +- src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 4 +- .../UI/Windows/SettingsWindow.axaml.cs | 2 +- src/Ryujinx/Updater.cs | 8 ++-- 13 files changed, 82 insertions(+), 40 deletions(-) rename src/Ryujinx/{App.axaml => RyujinxApp.axaml} (94%) rename src/Ryujinx/{App.axaml.cs => RyujinxApp.axaml.cs} (94%) diff --git a/src/Ryujinx/Common/ApplicationHelper.cs b/src/Ryujinx/Common/ApplicationHelper.cs index db5961347..1c6b53dee 100644 --- a/src/Ryujinx/Common/ApplicationHelper.cs +++ b/src/Ryujinx/Common/ApplicationHelper.cs @@ -146,7 +146,7 @@ namespace Ryujinx.Ava.Common var cancellationToken = new CancellationTokenSource(); UpdateWaitWindow waitingDialog = new( - App.FormatTitle(LocaleKeys.DialogNcaExtractionTitle), + RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle), LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogNcaExtractionMessage, ncaSectionType, Path.GetFileName(titleFilePath)), cancellationToken); @@ -268,10 +268,9 @@ namespace Ryujinx.Ava.Common { Dispatcher.UIThread.Post(waitingDialog.Close); - NotificationHelper.Show( - App.FormatTitle(LocaleKeys.DialogNcaExtractionTitle), - $"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}", - NotificationType.Information); + NotificationHelper.ShowInformation( + RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle), + $"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}"); } } diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 3c24b8e27..2ec60ac70 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -65,7 +65,7 @@ namespace Ryujinx.Ava } public static AppBuilder BuildAvaloniaApp() => - AppBuilder.Configure() + AppBuilder.Configure() .UsePlatformDetect() .With(new X11PlatformOptions { @@ -100,7 +100,7 @@ namespace Ryujinx.Ava // Delete backup files after updating. Task.Run(Updater.CleanupUpdate); - Console.Title = $"{App.FullAppName} Console {Version}"; + Console.Title = $"{RyujinxApp.FullAppName} Console {Version}"; // Hook unhandled exception and process exit events. AppDomain.CurrentDomain.UnhandledException += (sender, e) @@ -225,7 +225,7 @@ namespace Ryujinx.Ava private static void PrintSystemInfo() { - Logger.Notice.Print(LogClass.Application, $"{App.FullAppName} Version: {Version}"); + Logger.Notice.Print(LogClass.Application, $"{RyujinxApp.FullAppName} Version: {Version}"); SystemInfo.Gather().Print(); var enabledLogLevels = Logger.GetEnabledLevels().ToArray(); diff --git a/src/Ryujinx/App.axaml b/src/Ryujinx/RyujinxApp.axaml similarity index 94% rename from src/Ryujinx/App.axaml rename to src/Ryujinx/RyujinxApp.axaml index 5c96f97f2..e07d7ff26 100644 --- a/src/Ryujinx/App.axaml +++ b/src/Ryujinx/RyujinxApp.axaml @@ -1,5 +1,5 @@ diff --git a/src/Ryujinx/App.axaml.cs b/src/Ryujinx/RyujinxApp.axaml.cs similarity index 94% rename from src/Ryujinx/App.axaml.cs rename to src/Ryujinx/RyujinxApp.axaml.cs index 9c1170d08..bbef20aa0 100644 --- a/src/Ryujinx/App.axaml.cs +++ b/src/Ryujinx/RyujinxApp.axaml.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Input.Platform; using Avalonia.Markup.Xaml; using Avalonia.Platform; using Avalonia.Styling; @@ -19,7 +20,7 @@ using System.Diagnostics; namespace Ryujinx.Ava { - public class App : Application + public class RyujinxApp : Application { internal static string FormatTitle(LocaleKeys? windowTitleKey = null) => windowTitleKey is null @@ -32,8 +33,11 @@ namespace Ryujinx.Ava .ApplicationLifetime.Cast() .MainWindow.Cast(); - public static IClassicDesktopStyleApplicationLifetime DesktopLifetime => Current! - .ApplicationLifetime.Cast(); + public static bool IsClipboardAvailable(out IClipboard clipboard) + { + clipboard = MainWindow.Clipboard; + return clipboard != null; + } public static void SetTaskbarProgress(TaskBarProgressBarState state) => MainWindow.PlatformFeatures.SetTaskBarProgressBarState(state); public static void SetTaskbarProgressValue(ulong current, ulong total) => MainWindow.PlatformFeatures.SetTaskBarProgressBarValue(current, total); @@ -135,7 +139,7 @@ namespace Ryujinx.Ava }; public static ThemeVariant DetectSystemTheme() => - Current is App { PlatformSettings: not null } app + Current is RyujinxApp { PlatformSettings: not null } app ? ConvertThemeVariant(app.PlatformSettings.GetColorValues().ThemeVariant) : ThemeVariant.Default; } diff --git a/src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs b/src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs index 6cdff3463..5b0730d5a 100644 --- a/src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs +++ b/src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs @@ -43,17 +43,19 @@ namespace Ryujinx.Ava.UI.Controls if (sender is not Button { Content: TextBlock idText }) return; + + if (!RyujinxApp.IsClipboardAvailable(out var clipboard)) + return; - if (App.MainWindow.Clipboard is { } clipboard) - { - var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text); - if (appData is null) - return; + var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text); + if (appData is null) + return; + + await clipboard.SetTextAsync(appData.IdString); - await clipboard.SetTextAsync(appData.IdString); - - NotificationHelper.Show("Copied Title ID", $"{appData.Name} ({appData.IdString})", NotificationType.Information); - } + NotificationHelper.ShowInformation( + "Copied Title ID", + $"{appData.Name} ({appData.IdString})"); } } } diff --git a/src/Ryujinx/UI/Helpers/NotificationHelper.cs b/src/Ryujinx/UI/Helpers/NotificationHelper.cs index 656a8b52f..74029a4b1 100644 --- a/src/Ryujinx/UI/Helpers/NotificationHelper.cs +++ b/src/Ryujinx/UI/Helpers/NotificationHelper.cs @@ -62,9 +62,46 @@ namespace Ryujinx.Ava.UI.Helpers _notifications.Add(new Notification(title, text, type, delay, onClick, onClose)); } - public static void ShowError(string message) - { - Show(LocaleManager.Instance[LocaleKeys.DialogErrorTitle], $"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}", NotificationType.Error); - } + public static void ShowError(string message) => + ShowError( + LocaleManager.Instance[LocaleKeys.DialogErrorTitle], + $"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}" + ); + + public static void ShowInformation(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) => + Show( + title, + text, + NotificationType.Information, + waitingExit, + onClick, + onClose); + + public static void ShowSuccess(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) => + Show( + title, + text, + NotificationType.Success, + waitingExit, + onClick, + onClose); + + public static void ShowWarning(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) => + Show( + title, + text, + NotificationType.Warning, + waitingExit, + onClick, + onClose); + + public static void ShowError(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) => + Show( + title, + text, + NotificationType.Error, + waitingExit, + onClick, + onClose); } } diff --git a/src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs index 23d0f963c..607bff792 100644 --- a/src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs @@ -51,7 +51,7 @@ namespace Ryujinx.Ava.UI.ViewModels public AboutWindowViewModel() { - Version = App.FullAppName + "\n" + Program.Version; + Version = RyujinxApp.FullAppName + "\n" + Program.Version; UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value); ThemeManager.ThemeChanged += ThemeManager_ThemeChanged; @@ -64,7 +64,7 @@ namespace Ryujinx.Ava.UI.ViewModels private void UpdateLogoTheme(string theme) { - bool isDarkTheme = theme == "Dark" || (theme == "Auto" && App.DetectSystemTheme() == ThemeVariant.Dark); + bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark); string basePath = "resm:Ryujinx.UI.Common.Resources."; string themeSuffix = isDarkTheme ? "Dark.png" : "Light.png"; diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index f7cd83ed6..3ff05785a 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -2051,7 +2051,7 @@ namespace Ryujinx.Ava.UI.ViewModels Dispatcher.UIThread.InvokeAsync(() => { - Title = App.FormatTitle(); + Title = RyujinxApp.FormatTitle(); }); } diff --git a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs index 6182e6b50..9a940c938 100644 --- a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Ava.UI.Windows InitializeComponent(); - Title = App.FormatTitle(LocaleKeys.Amiibo); + Title = RyujinxApp.FormatTitle(LocaleKeys.Amiibo); } public AmiiboWindow() @@ -27,7 +27,7 @@ namespace Ryujinx.Ava.UI.Windows if (Program.PreviewerDetached) { - Title = App.FormatTitle(LocaleKeys.Amiibo); + Title = RyujinxApp.FormatTitle(LocaleKeys.Amiibo); } } diff --git a/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs b/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs index 8c8d56b34..2fc9617fb 100644 --- a/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Ava.UI.Windows InitializeComponent(); - Title = App.FormatTitle(LocaleKeys.CheatWindowTitle); + Title = RyujinxApp.FormatTitle(LocaleKeys.CheatWindowTitle); } public CheatWindow(VirtualFileSystem virtualFileSystem, string titleId, string titleName, string titlePath) @@ -93,7 +93,7 @@ namespace Ryujinx.Ava.UI.Windows DataContext = this; - Title = App.FormatTitle(LocaleKeys.CheatWindowTitle); + Title = RyujinxApp.FormatTitle(LocaleKeys.CheatWindowTitle); } public void Save() diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index 88e82c89e..e621b42ec 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -86,7 +86,7 @@ namespace Ryujinx.Ava.UI.Windows UiHandler = new AvaHostUIHandler(this); - ViewModel.Title = App.FormatTitle(); + ViewModel.Title = RyujinxApp.FormatTitle(); TitleBar.ExtendsContentIntoTitleBar = !ConfigurationState.Instance.ShowTitleBar; TitleBar.TitleBarHitTestType = (ConfigurationState.Instance.ShowTitleBar) ? TitleBarHitTestType.Simple : TitleBarHitTestType.Complex; @@ -117,7 +117,7 @@ namespace Ryujinx.Ava.UI.Windows /// private static void OnPlatformColorValuesChanged(object sender, PlatformColorValues e) { - if (Application.Current is App app) + if (Application.Current is RyujinxApp app) app.ApplyConfiguredTheme(ConfigurationState.Instance.UI.BaseStyle); } diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs index b004d9fba..0c0345107 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Ava.UI.Windows public SettingsWindow(VirtualFileSystem virtualFileSystem, ContentManager contentManager) { - Title = App.FormatTitle(LocaleKeys.Settings); + Title = RyujinxApp.FormatTitle(LocaleKeys.Settings); DataContext = ViewModel = new SettingsViewModel(virtualFileSystem, contentManager); diff --git a/src/Ryujinx/Updater.cs b/src/Ryujinx/Updater.cs index 21d991d97..3d4f11317 100644 --- a/src/Ryujinx/Updater.cs +++ b/src/Ryujinx/Updater.cs @@ -76,7 +76,7 @@ namespace Ryujinx.Ava if (!Version.TryParse(Program.Version, out Version currentVersion)) { - Logger.Error?.Print(LogClass.Application, $"Failed to convert the current {App.FullAppName} version!"); + Logger.Error?.Print(LogClass.Application, $"Failed to convert the current {RyujinxApp.FullAppName} version!"); await ContentDialogHelper.CreateWarningDialog( LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedMessage], @@ -159,7 +159,7 @@ namespace Ryujinx.Ava if (!Version.TryParse(_buildVer, out Version newVersion)) { - Logger.Error?.Print(LogClass.Application, $"Failed to convert the received {App.FullAppName} version from GitHub!"); + Logger.Error?.Print(LogClass.Application, $"Failed to convert the received {RyujinxApp.FullAppName} version from GitHub!"); await ContentDialogHelper.CreateWarningDialog( LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage], @@ -266,7 +266,7 @@ namespace Ryujinx.Ava SubHeader = LocaleManager.Instance[LocaleKeys.UpdaterDownloading], IconSource = new SymbolIconSource { Symbol = Symbol.Download }, ShowProgressBar = true, - XamlRoot = App.MainWindow, + XamlRoot = RyujinxApp.MainWindow, }; taskDialog.Opened += (s, e) => @@ -490,7 +490,7 @@ namespace Ryujinx.Ava bytesWritten += readSize; taskDialog.SetProgressBarState(GetPercentage(bytesWritten, totalBytes), TaskDialogProgressState.Normal); - App.SetTaskbarProgressValue(bytesWritten, totalBytes); + RyujinxApp.SetTaskbarProgressValue(bytesWritten, totalBytes); updateFileStream.Write(buffer, 0, readSize); }