Activation service

This commit is contained in:
2024-03-14 16:31:26 +01:00
Unverified
parent fa71543773
commit c9d81fe966
26 changed files with 356 additions and 154 deletions

View File

@@ -1,17 +1,19 @@
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using SimpleToolkit.UI.WinUI.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.Common;
namespace VDownload.Services.UI.Notifications
{
public interface INotificationsService
public interface INotificationsService : IInitializableService<Window>
{
void Initialize(Action notificationInvoked);
void SendNotification(string title, IEnumerable<string> message);
}
@@ -19,7 +21,15 @@ namespace VDownload.Services.UI.Notifications
public class NotificationsService : INotificationsService
{
#region CONSTRCUTORS
#region FIELDS
protected Window _window;
#endregion
#region CONSTRUCTORS
~NotificationsService()
{
@@ -32,12 +42,14 @@ namespace VDownload.Services.UI.Notifications
#region PUBLIC METHODS
public void Initialize(Action notificationInvoked)
public async Task Initialize(Window window) => await Task.Run(() =>
{
AppNotificationManager.Default.NotificationInvoked += (obj, args) => notificationInvoked.Invoke();
_window = window;
AppNotificationManager.Default.NotificationInvoked += NotificationInvoked;
AppNotificationManager.Default.Register();
}
});
public void SendNotification(string title, IEnumerable<string> message)
{
@@ -54,5 +66,13 @@ namespace VDownload.Services.UI.Notifications
}
#endregion
#region PRIVATE METHODS
private void NotificationInvoked(AppNotificationManager sender, AppNotificationActivatedEventArgs args) => WindowHelper.ShowWindow(_window);
#endregion
}
}

View File

@@ -13,5 +13,10 @@
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="SimpleToolkit.UI.WinUI.Helpers" Version="1.7.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
</ItemGroup>
</Project>