Improving stability for the notification issue reported in #182

This commit is contained in:
Robin 2020-04-14 12:31:52 +02:00
parent 3055d42689
commit 87f3b6a871
3 changed files with 204 additions and 177 deletions

View file

@ -43,6 +43,10 @@ namespace GreenshotPlugin.Core
foreach (var service in services)
{
if (service == null)
{
continue;
}
currentServices.Add(service);
}
}

View file

@ -23,6 +23,7 @@ using System;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using Windows.Foundation.Metadata;
using Windows.UI.Notifications;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
@ -149,8 +150,15 @@ namespace GreenshotWin10Plugin
}
toast.Dismissed += ToastDismissedHandler;
toast.Failed += ToastOnFailed;
try
{
toastNotifier.Show(toast);
}
catch (Exception ex)
{
Log.Error("Couldn't show notification.", ex);
}
}
private void ToastOnFailed(ToastNotification sender, ToastFailedEventArgs args)
{
@ -172,5 +180,20 @@ namespace GreenshotWin10Plugin
{
ShowMessage(message, timeout, onClickAction, onClosedAction);
}
/// <summary>
/// Factory method, helping with checking if the notification service is even available
/// </summary>
/// <returns>ToastNotificationService</returns>
public static ToastNotificationService Create()
{
if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Background.ToastNotificationActionTrigger"))
{
return new ToastNotificationService();
}
Log.Warn("ToastNotificationActionTrigger not available.");
return null;
}
}
}

View file

@ -63,7 +63,7 @@ namespace GreenshotWin10Plugin
return false;
}
SimpleServiceProvider.Current.AddService<INotificationService>(new ToastNotificationService());
SimpleServiceProvider.Current.AddService<INotificationService>(ToastNotificationService.Create());
// Set this as IOcrProvider
SimpleServiceProvider.Current.AddService<IOcrProvider>(new Win10OcrProvider());
// Add the processor