rename NotificationHelper to RyujinxNotificationManager,

rename instance method names.
Additionally clarified what the math is in the notification manager margin parameter.
This commit is contained in:
GreemDev 2025-11-26 17:12:35 -06:00
parent d9128ece5b
commit 8ec1a3a594
12 changed files with 49 additions and 40 deletions

View file

@ -264,7 +264,7 @@ namespace Ryujinx.Ava.Common
{
Dispatcher.UIThread.Post(waitingDialog.Close);
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
$"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}");
}
@ -380,7 +380,7 @@ namespace Ryujinx.Ava.Common
{
Dispatcher.UIThread.Post(waitingDialog.Close);
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
$"{updateName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}");
}

View file

@ -1,9 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
namespace Ryujinx.Ava.UI.Helpers
{
public static class ControlExtensions
{
public static RyujinxNotificationManager CreateNotificationManager(
this Window window,
NotificationPosition visiblePosition = NotificationPosition.BottomRight,
int maxItems = RyujinxNotificationManager.MaxNotifications,
Thickness? margin = null
) => new(window, visiblePosition, maxItems, margin);
extension(Control ctrl)
{
public int GridRow

View file

@ -4,25 +4,24 @@ using Avalonia.Controls.Notifications;
using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Common;
using Ryujinx.Ava.UI.SetupWizard;
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace Ryujinx.Ava.UI.Helpers
{
public class NotificationHelper
public class RyujinxNotificationManager
{
public static NotificationHelper Shared { get; set; }
public static RyujinxNotificationManager Shared { get; set; }
private const int MaxNotifications = 4;
public const int MaxNotifications = 4;
private const int NotificationDelayInMs = 5000;
private readonly WindowNotificationManager _notificationManager;
private readonly BlockingCollection<Notification> _notifications = new();
public NotificationHelper(Window host,
public RyujinxNotificationManager(Window host,
NotificationPosition visiblePosition = NotificationPosition.BottomRight,
int maxItems = MaxNotifications,
Thickness? margin = null)
@ -63,9 +62,9 @@ namespace Ryujinx.Ava.UI.Helpers
public static void Show(string title, string text, NotificationType type, bool waitingExit = false,
Action onClick = null, Action onClose = null)
=> Shared?.Notify(title, text, type, waitingExit, onClick, onClose);
=> Shared?.Send(title, text, type, waitingExit, onClick, onClose);
public void Notify(string title, string text, NotificationType type, bool waitingExit = false,
public void Send(string title, string text, NotificationType type, bool waitingExit = false,
Action onClick = null, Action onClose = null)
{
TimeSpan delay = waitingExit
@ -77,9 +76,9 @@ namespace Ryujinx.Ava.UI.Helpers
#region Instance notification senders
public void NotifyInformation(string title, string text, bool waitingExit = false, Action onClick = null,
public void Information(string title, string text, bool waitingExit = false, Action onClick = null,
Action onClose = null) =>
Notify(
Send(
title,
text,
NotificationType.Information,
@ -87,9 +86,9 @@ namespace Ryujinx.Ava.UI.Helpers
onClick,
onClose);
public void NotifySuccess(string title, string text, bool waitingExit = false, Action onClick = null,
public void Success(string title, string text, bool waitingExit = false, Action onClick = null,
Action onClose = null) =>
Notify(
Send(
title,
text,
NotificationType.Success,
@ -97,9 +96,9 @@ namespace Ryujinx.Ava.UI.Helpers
onClick,
onClose);
public void NotifyWarning(string title, string text, bool waitingExit = false, Action onClick = null,
public void Warning(string title, string text, bool waitingExit = false, Action onClick = null,
Action onClose = null) =>
Notify(
Send(
title,
text,
NotificationType.Warning,
@ -107,9 +106,9 @@ namespace Ryujinx.Ava.UI.Helpers
onClick,
onClose);
public void NotifyError(string title, string text, bool waitingExit = false, Action onClick = null,
public void Error(string title, string text, bool waitingExit = false, Action onClick = null,
Action onClose = null) =>
Notify(
Send(
title,
text,
NotificationType.Error,
@ -117,8 +116,8 @@ namespace Ryujinx.Ava.UI.Helpers
onClick,
onClose);
public void NotifyError(string message, bool waitingExit = false) =>
NotifyError(
public void Error(string message, bool waitingExit = false) =>
Error(
LocaleManager.Instance[LocaleKeys.DialogErrorTitle],
$"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}",
waitingExit: waitingExit

View file

@ -79,14 +79,14 @@ namespace Ryujinx.Ava.UI.SetupWizard.Pages
SystemVersion installedFwVer = RyujinxApp.MainWindow.ContentManager.GetCurrentFirmwareVersion();
if (installedFwVer != null)
{
Notifications.NotifyInformation(
NotificationManager.Information(
"Firmware installed",
$"Installed firmware version {installedFwVer.VersionString}."
);
}
else
{
Notifications.NotifyError(
NotificationManager.Error(
"Firmware not installed",
$"It seems some error occurred when trying to install the firmware at path '{FirmwareSourcePath}'." +
"\nDid that folder contain a firmware dump?"
@ -107,7 +107,7 @@ namespace Ryujinx.Ava.UI.SetupWizard.Pages
}
catch (Exception e)
{
Notifications.NotifyError(e.Message, waitingExit: true);
NotificationManager.Error(e.Message, waitingExit: true);
return Result.Fail;
}

View file

@ -55,18 +55,18 @@ namespace Ryujinx.Ava.UI.SetupWizard.Pages
ContentManager.InstallKeys(directory, systemDirectory);
Notifications.NotifyInformation(
NotificationManager.Information(
title: LocaleManager.Instance[LocaleKeys.RyujinxInfo],
text: LocaleManager.Instance[LocaleKeys.DialogKeysInstallerKeysInstallSuccessMessage]);
}
catch (InvalidFirmwarePackageException ifwpe)
{
Notifications.NotifyError(ifwpe.Message, waitingExit: true);
NotificationManager.Error(ifwpe.Message, waitingExit: true);
return Result.Failure(NoKeysFoundInFolder.Shared);
}
catch (MissingKeyException ex)
{
Notifications.NotifyError(ex.ToString(), waitingExit: true);
NotificationManager.Error(ex.ToString(), waitingExit: true);
return Result.Failure(NoKeysFoundInFolder.Shared);
}
catch (Exception ex)
@ -78,7 +78,7 @@ namespace Ryujinx.Ava.UI.SetupWizard.Pages
LocaleKeys.DialogKeysInstallerKeysNotFoundErrorMessage, directory);
}
Notifications.NotifyError(message, waitingExit: true);
NotificationManager.Error(message, waitingExit: true);
return Result.Failure(new MessageError(message));
}

View file

@ -14,13 +14,14 @@ namespace Ryujinx.Ava.UI.SetupWizard
public bool HasFirmware => RyujinxApp.MainWindow.ContentManager.GetCurrentFirmwareVersion() != null;
public NotificationHelper Notification { get; private set; }
public RyujinxNotificationManager NotificationManager { get; private set; }
public async Task Start()
{
Notification = new NotificationHelper(
wizardWindow,
NotificationManager = wizardWindow.CreateNotificationManager(
// I wanted to do bottom center but that...literally just shows top center? Okay.
// Fuck it, weird window height hack to do it instead.
// 120 is not exact, just a random number. Looks fine though.
NotificationPosition.TopCenter,
margin: new Thickness(0, wizardWindow.Height - 120, 0, 0)
);
@ -47,7 +48,7 @@ namespace Ryujinx.Ava.UI.SetupWizard
if (_configWasModified)
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.GlobalConfigurationPath);
Notification = null;
NotificationManager = null;
wizardWindow.Close();
RyujinxSetupWizardWindow.IsOpen = false;
}
@ -78,7 +79,7 @@ namespace Ryujinx.Ava.UI.SetupWizard
{
if (!RyujinxApp.MainWindow.VirtualFileSystem.HasKeySet)
{
Notification.NotifyError("Keys still seem to not be installed. Please try again.");
NotificationManager.Error("Keys still seem to not be installed. Please try again.");
return false;
}

View file

@ -48,7 +48,7 @@ namespace Ryujinx.Ava.UI.SetupWizard
where TControl : RyujinxControl<TViewModel>, new()
where TViewModel : SetupWizardPageContext, new()
{
boundViewModel = new() { Notifications = ownerWizard.Notification };
boundViewModel = new() { NotificationManager = ownerWizard.NotificationManager };
return WithContent<TControl>(boundViewModel);
}

View file

@ -6,7 +6,7 @@ namespace Ryujinx.Ava.UI.SetupWizard
{
public abstract class SetupWizardPageContext : BaseModel
{
public NotificationHelper Notifications { get; init; }
public RyujinxNotificationManager NotificationManager { get; init; }
public abstract Result CompleteStep();
}

View file

@ -1955,14 +1955,14 @@ namespace Ryujinx.Ava.UI.ViewModels
{
if (ConfigurationState.Instance.Debug.DebuggerSuspendOnStart)
{
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
LocaleManager.Instance[LocaleKeys.NotificationLaunchCheckSuspendOnStartTitle],
LocaleManager.Instance[LocaleKeys.NotificationLaunchCheckSuspendOnStartMessage]);
}
if (ConfigurationState.Instance.Debug.EnableGdbStub)
{
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.NotificationLaunchCheckGdbStubTitle, ConfigurationState.Instance.Debug.GdbStubPort.Value),
LocaleManager.Instance[LocaleKeys.NotificationLaunchCheckGdbStubMessage]);
}
@ -1981,7 +1981,7 @@ namespace Ryujinx.Ava.UI.ViewModels
_ => LocaleKeys.SettingsTabSystemDramSize4GiB,
};
NotificationHelper.ShowWarning(
RyujinxNotificationManager.ShowWarning(
LocaleManager.Instance.UpdateAndGetDynamicValue(
LocaleKeys.NotificationLaunchCheckDramSizeTitle,
LocaleManager.Instance[memoryConfigurationLocaleKey]

View file

@ -61,7 +61,7 @@ namespace Ryujinx.Ava.UI.Views.Dialog
await clipboard.SetTextAsync(appData.IdString);
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
"Copied Title ID",
$"{appData.Name} ({appData.IdString})");
}

View file

@ -61,7 +61,7 @@ namespace Ryujinx.Ava.UI.Views.Misc
await clipboard.SetTextAsync(appData.IdString);
NotificationHelper.ShowInformation(
RyujinxNotificationManager.ShowInformation(
"Copied Title ID",
$"{appData.Name} ({appData.IdString})");
}

View file

@ -135,7 +135,7 @@ namespace Ryujinx.Ava.UI.Windows
{
base.OnApplyTemplate(e);
NotificationHelper.Shared = new NotificationHelper(this);
RyujinxNotificationManager.Shared = new RyujinxNotificationManager(this);
Executor.ExecuteBackgroundAsync(async () =>
{