Skip to content

Commit

Permalink
[Feat]》 添加AppNotificationService。
Browse files Browse the repository at this point in the history
  • Loading branch information
zhh135 committed Jul 15, 2024
1 parent 31d43f7 commit f32305c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/HyPlayer.App/Interfaces/Services/IAppNotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Specialized;

namespace HyPlayer.Interfaces.Services;

public interface IAppNotificationService
{
void Initialize();

bool Show(string payload);

NameValueCollection ParseArguments(string arguments);

void Unregister();
}
52 changes: 52 additions & 0 deletions src/HyPlayer.App/Services/AppNotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Specialized;
using System.Web;

using HyPlayer.Interfaces.Services;

using Microsoft.Windows.AppNotifications;

namespace HyPlayer.Services;

public class AppNotificationService : IAppNotificationService
{
public AppNotificationService()
{
}

~AppNotificationService()
{
Unregister();
}

public void Initialize()
{
AppNotificationManager.Default.NotificationInvoked += OnNotificationInvoked;

AppNotificationManager.Default.Register();
}

public void OnNotificationInvoked(AppNotificationManager sender, AppNotificationActivatedEventArgs args)
{
throw new NotImplementedException();
}

public bool Show(string payload)
{
var appNotification = new AppNotification(payload);

AppNotificationManager.Default.Show(appNotification);

return appNotification.Id != 0;
}

public NameValueCollection ParseArguments(string arguments)
{
return HttpUtility.ParseQueryString(arguments);
}

public void Unregister()
{
AppNotificationManager.Default.Unregister();
}
}

0 comments on commit f32305c

Please sign in to comment.