From ac96c552dad46c40908cb48d41b465bbafb14c2d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 8 May 2017 00:42:56 +0300 Subject: [PATCH] Add notification setting values --- DesktopToast/ToastManager.cs | 15 ++++++++++++++- DesktopToast/ToastResult.cs | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/DesktopToast/ToastManager.cs b/DesktopToast/ToastManager.cs index feb9b20..0b8a35d 100644 --- a/DesktopToast/ToastManager.cs +++ b/DesktopToast/ToastManager.cs @@ -334,6 +334,19 @@ private static async Task CheckInstallShortcut(ToastRequest request) /// Result of showing a toast private static async Task ShowBaseAsync(XmlDocument document, string appId) { + var notifier = ToastNotificationManager.CreateToastNotifier(appId); + switch (notifier.Setting) + { + case NotificationSetting.DisabledForApplication: + return ToastResult.DisabledForApplication; + case NotificationSetting.DisabledForUser: + return ToastResult.DisabledForUser; + case NotificationSetting.DisabledByGroupPolicy: + return ToastResult.DisabledByGroupPolicy; + case NotificationSetting.DisabledByManifest: + return ToastResult.DisabledByManifest; + } + // Create a toast and prepare to handle toast events. var toast = new ToastNotification(document); var tcs = new TaskCompletionSource(); @@ -368,7 +381,7 @@ private static async Task ShowBaseAsync(XmlDocument document, strin toast.Failed += failed; // Show a toast. - ToastNotificationManager.CreateToastNotifier(appId).Show(toast); + notifier.Show(toast); // Wait for the result. var result = await tcs.Task; diff --git a/DesktopToast/ToastResult.cs b/DesktopToast/ToastResult.cs index 32ebf34..2ffe5ed 100644 --- a/DesktopToast/ToastResult.cs +++ b/DesktopToast/ToastResult.cs @@ -11,6 +11,30 @@ public enum ToastResult /// Unavailable = 0, + /// + /// The user has disabled notifications for this app. + /// + /// This corresponds to NotificationSetting.DisabledForApplication setting. + DisabledForApplication, + + /// + /// The user or administrator has disabled all notifications for this user on this computer. + /// + /// This corresponds to NotificationSetting.DisabledForUser setting. + DisabledForUser, + + /// + /// An administrator has disabled all notifications on this computer through group policy. + /// + /// This corresponds to NotificationSetting.DisabledByGroupPolicy setting. + DisabledByGroupPolicy, + + /// + /// This app has not declared itself toast capable in its package.appxmanifest file. + /// + /// This corresponds to NotificationSetting.DisabledByManifest setting. + DisabledByManifest, + /// /// Toast request is invalid. ///