mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Improving stability for the notification issue reported in #182
This commit is contained in:
parent
3055d42689
commit
87f3b6a871
3 changed files with 204 additions and 177 deletions
|
@ -43,6 +43,10 @@ namespace GreenshotPlugin.Core
|
|||
|
||||
foreach (var service in services)
|
||||
{
|
||||
if (service == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
currentServices.Add(service);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue