diff options
author | Ac_K <Acoustik666@gmail.com> | 2023-01-21 02:57:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-21 02:57:37 +0100 |
commit | a47824f96101a1c1e63b7622f0c4e61ba6345a98 (patch) | |
tree | a90592f9084c5243eefe3b542301168b52beb2d2 /Ryujinx.Ava/UI/Helpers/NotificationHelper.cs | |
parent | 8474d52778d6bc45146b59a1fc921e6702f4b96a (diff) |
Ava UI: Add Notifications and Cleanup (#4275)1.1.581
* Ava UI: Add Notifications and Cleanup
* Revert notifications on ErrorDialog
* remove unused code from game list views
* Fix cast
Diffstat (limited to 'Ryujinx.Ava/UI/Helpers/NotificationHelper.cs')
-rw-r--r-- | Ryujinx.Ava/UI/Helpers/NotificationHelper.cs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Ryujinx.Ava/UI/Helpers/NotificationHelper.cs b/Ryujinx.Ava/UI/Helpers/NotificationHelper.cs new file mode 100644 index 00000000..7e2afb8b --- /dev/null +++ b/Ryujinx.Ava/UI/Helpers/NotificationHelper.cs @@ -0,0 +1,65 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Notifications; +using Avalonia.Threading; +using Ryujinx.Ava.Common.Locale; +using System; +using System.Collections.Concurrent; +using System.Threading; +using System.Threading.Tasks; + +namespace Ryujinx.Ava.UI.Helpers +{ + public static class NotificationHelper + { + private const int MaxNotifications = 4; + private const int NotificationDelayInMs = 5000; + + private static WindowNotificationManager _notificationManager; + + private static readonly ManualResetEvent _templateAppliedEvent = new(false); + private static readonly BlockingCollection<Notification> _notifications = new(); + + public static void SetNotificationManager(Window host) + { + _notificationManager = new WindowNotificationManager(host) + { + Position = NotificationPosition.BottomRight, + MaxItems = MaxNotifications, + Margin = new Thickness(0, 0, 15, 40) + }; + + _notificationManager.TemplateApplied += (sender, args) => + { + _templateAppliedEvent.Set(); + }; + + Task.Run(async () => + { + _templateAppliedEvent.WaitOne(); + + foreach (var notification in _notifications.GetConsumingEnumerable()) + { + Dispatcher.UIThread.Post(() => + { + _notificationManager.Show(notification); + }); + + await Task.Delay(NotificationDelayInMs / MaxNotifications); + } + }); + } + + public static void Show(string title, string text, NotificationType type, bool waitingExit = false, Action onClick = null, Action onClose = null) + { + var delay = waitingExit ? TimeSpan.FromMilliseconds(0) : TimeSpan.FromMilliseconds(NotificationDelayInMs); + + _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); + } + } +}
\ No newline at end of file |