You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
10 months ago
|
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
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|