Browse Source

Add NotificationServiceExtensions for package completion handling

pull/438/head
Ionite 10 months ago
parent
commit
6a151a5c2f
No known key found for this signature in database
  1. 54
      StabilityMatrix.Avalonia/Extensions/NotificationServiceExtensions.cs

54
StabilityMatrix.Avalonia/Extensions/NotificationServiceExtensions.cs

@ -0,0 +1,54 @@
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using DesktopNotifications;
using NLog;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Core.Models.PackageModification;
using StabilityMatrix.Core.Models.Settings;
namespace StabilityMatrix.Avalonia.Extensions;
public static class NotificationServiceExtensions
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static void OnPackageInstallCompleted(
this INotificationService notificationService,
IPackageModificationRunner runner
)
{
OnPackageInstallCompletedAsync(notificationService, runner)
.SafeFireAndForget(ex => Logger.Error(ex, "Error Showing Notification"));
}
private static async Task OnPackageInstallCompletedAsync(
this INotificationService notificationService,
IPackageModificationRunner runner
)
{
if (runner.Failed)
{
Logger.Error(runner.Exception, "Error Installing Package");
await notificationService.ShowAsync(
NotificationKey.Package_Install_Failed,
new Notification
{
Title = runner.ModificationFailedTitle,
Body = runner.ModificationFailedMessage
}
);
}
else
{
await notificationService.ShowAsync(
NotificationKey.Package_Install_Completed,
new Notification
{
Title = runner.ModificationCompleteTitle,
Body = runner.ModificationCompleteMessage
}
);
}
}
}
Loading…
Cancel
Save