mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-25 03:09:54 +08:00
74 lines
2.7 KiB
C#
74 lines
2.7 KiB
C#
using System.Application.Models;
|
|
using System.Security;
|
|
using System.Threading.Tasks;
|
|
using static System.Application.KeyConstants;
|
|
|
|
namespace System.Application.Services
|
|
{
|
|
/// <inheritdoc cref="INotificationService{TNotificationType, TEntrance, TNotificationService}"/>
|
|
public interface INotificationService : INotificationService<NotificationType, Entrance, INotificationService>
|
|
{
|
|
static INotificationService Instance => DI.Get<INotificationService>();
|
|
|
|
/// <summary>
|
|
/// 显示从服务端获取到通知纪录
|
|
/// </summary>
|
|
/// <param name="notification"></param>
|
|
void Notify(NotificationRecordDTO notification)
|
|
=> Notify(notification.Content, notification.Type, title: notification.Title);
|
|
|
|
/// <summary>
|
|
/// 显示从服务端获取到通知纪录
|
|
/// </summary>
|
|
/// <param name="rsp"></param>
|
|
/// <param name="type"></param>
|
|
static async void Notify(IApiResponse<NotificationRecordDTO?> rsp, ActiveUserType type)
|
|
{
|
|
if (rsp.IsSuccess && rsp.Content != null)
|
|
{
|
|
if (type == ActiveUserType.OnStartup)
|
|
{
|
|
await IStorage.Instance.SetAsync(ON_LAST_STARTUP_NOTIFICATION_RECORD_ID, rsp.Content.Id);
|
|
}
|
|
|
|
if (!rsp.Content.Type.IsDefined())
|
|
{
|
|
// 新增通知类型不能兼容旧版本
|
|
return;
|
|
}
|
|
|
|
if (rsp.Content.Type == NotificationType.Announcement)
|
|
{
|
|
var announcementService = DI.Get_Nullable<IAnnouncementService>();
|
|
if (announcementService != null)
|
|
{
|
|
var isShow = announcementService.Show(rsp.Content);
|
|
if (isShow) return;
|
|
}
|
|
}
|
|
|
|
Instance.Notify(rsp.Content);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最后一次收到的通知ID
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
static Task<Guid?> GetLastNotificationRecordId() => IStorage.Instance.GetAsync<Guid?>(ON_LAST_STARTUP_NOTIFICATION_RECORD_ID);
|
|
|
|
/// <summary>
|
|
/// NotifyIcon / TrayIcon 右下角托盘菜单助手类
|
|
/// </summary>
|
|
public abstract class NotifyIconHelper
|
|
{
|
|
protected NotifyIconHelper() => throw new NotSupportedException();
|
|
|
|
/// <summary>
|
|
/// 托盘初始化是否完成
|
|
/// <para>注意:在 Windows 上托盘初始化之前调用气泡消息会导致托盘不显示</para>
|
|
/// </summary>
|
|
public static bool IsInitialized { get; protected set; }
|
|
}
|
|
}
|
|
} |