This commit is contained in:
Andrew Leader 2020-12-15 09:45:53 -08:00
Родитель 168bda8a13
Коммит 0f92052178
3 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -506,7 +506,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications
}
}
internal static void PrepForScheduledToast()
internal static void PreRegisterIdentityLessApp()
{
// For plain Win32 apps, we first have to have send a toast notification once before using scheduled toasts.
if (!_hasSentNotification && !DesktopBridgeHelpers.HasIdentity())

Просмотреть файл

@ -58,7 +58,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications
public void AddToSchedule(ScheduledToastNotification scheduledToast)
{
#if WIN32
ToastNotificationManagerCompat.PrepForScheduledToast();
ToastNotificationManagerCompat.PreRegisterIdentityLessApp();
PreprocessScheduledToast(scheduledToast);
#endif
@ -125,7 +125,16 @@ namespace Microsoft.Toolkit.Uwp.Notifications
/// </summary>
public NotificationSetting Setting
{
get => _notifier.Setting;
get
{
#if WIN32
// Just like scheduled notifications, apps need to have sent a notification
// before checking the setting value works
ToastNotificationManagerCompat.PreRegisterIdentityLessApp();
#endif
return _notifier.Setting;
}
}
#if WIN32

Просмотреть файл

@ -30,6 +30,12 @@ namespace Microsoft.Toolkit.Win32.WpfCore.SampleApp
private async void ButtonPopToast_Click(object sender, RoutedEventArgs e)
{
if (ToastNotificationManagerCompat.CreateToastNotifier().Setting != NotificationSetting.Enabled)
{
MessageBox.Show("Notifications are disabled from the system settings.");
return;
}
string title = "Andrew sent you a picture";
string content = "Check this out, The Enchantments!";
string image = "https://picsum.photos/364/202?image=883";