2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 16:33:43 -04:00

Notification overhaul and update to avaloniaui 0.10.7

This commit is contained in:
Xjph
2021-10-12 20:45:00 -02:30
parent 840ccad5bf
commit 5159500644
10 changed files with 279 additions and 75 deletions

View File

@ -0,0 +1,52 @@
using Observatory.Framework;
using System;
using System.Collections.Generic;
using Observatory.UI.Views;
using Observatory.UI.ViewModels;
namespace Observatory.NativeNotification
{
public class NativePopup
{
private Dictionary<Guid, NotificationView> notifications;
public NativePopup()
{
notifications = new();
}
public Guid InvokeNativeNotification(NotificationArgs notificationArgs)
{
var notificationGuid = Guid.NewGuid();
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
var notifyWindow = new NotificationView(notificationGuid) { DataContext = new NotificationViewModel(notificationArgs) };
notifyWindow.Closed += NotifyWindow_Closed;
notifications.Add(notificationGuid, notifyWindow);
notifyWindow.Show();
});
return notificationGuid;
}
private void NotifyWindow_Closed(object sender, EventArgs e)
{
var notification = (NotificationView)sender;
if (notifications.ContainsKey(notification.Guid))
notifications.Remove(notification.Guid);
}
public void CloseNotification(Guid guid)
{
if (notifications.ContainsKey(guid))
notifications[guid].Close();
}
public void UpdateNotification(Guid guid, NotificationArgs notificationArgs)
{
if (notifications.ContainsKey(guid))
notifications[guid].DataContext = new NotificationViewModel(notificationArgs);
}
}
}