2024-11-13 17:09:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.Notifications;
|
|
|
|
|
|
|
|
|
|
namespace detect.gui.Classes;
|
|
|
|
|
|
|
|
|
|
public abstract class NotificationService
|
|
|
|
|
{
|
|
|
|
|
private static WindowNotificationManager? _notificationManager;
|
|
|
|
|
|
|
|
|
|
private const int NotificationTimeout = 4;
|
|
|
|
|
|
|
|
|
|
public static void SetHostWindow(TopLevel? window)
|
|
|
|
|
{
|
|
|
|
|
var notificationManager = new WindowNotificationManager(window)
|
|
|
|
|
{
|
2024-11-27 15:20:42 +08:00
|
|
|
|
Position = NotificationPosition.TopRight,
|
2024-11-13 17:09:15 +08:00
|
|
|
|
MaxItems = 4
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_notificationManager = notificationManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Show(string title, string? message, NotificationType type,Action? onClick = null)
|
|
|
|
|
{
|
|
|
|
|
if (_notificationManager is { } nm)
|
|
|
|
|
{
|
|
|
|
|
nm.Show(
|
|
|
|
|
new Notification(
|
|
|
|
|
title,
|
|
|
|
|
message,
|
|
|
|
|
type,
|
|
|
|
|
new TimeSpan(0,0,0, NotificationTimeout),
|
|
|
|
|
onClick));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|