Exemple #1
0
        private async void NotificationHandler(object sender, UserNotificationChangedEventArgs e)
        {
            if (!IsListenerActive)
            {
                return;
            }
            if (e.ChangeKind != UserNotificationChangedKind.Added)
            {
                return;
            }
            try
            {
                var notifs = await Listener.GetNotificationsAsync(NotificationKinds.Toast);

                var newlyAdded = notifs.Except(Notifications, new NotificationComparer()).ToList();
                Conf.Log($"received {newlyAdded.Count} notification(s) from listener");
                NewNotificationPool.AddRange(newlyAdded);
                Notifications.AddRange(newlyAdded);
                foreach (var item in newlyAdded)
                {
                    Conf.CurrentConf.AddApp(new AppInfo(item.AppInfo)
                    {
                        ForwardingEnabled = !Conf.CurrentConf.MuteNewApps
                    });
                    var appIndex = Conf.CurrentConf.FindAppIndex(new AppInfo(item.AppInfo));
                    if (appIndex == -1 && !Conf.CurrentConf.MuteNewApps)
                    {
                        continue;
                    }
                    if (!Conf.CurrentConf.AppsToForward[appIndex].ForwardingEnabled)
                    {
                        continue;
                    }
                    Conf.Log($"marked notification #{item.Id} as pending, app: {item.AppInfo.AppUserModelId}");
                    UnsentNotificationPool.Add(new Protocol.Notification(item));
                }
                Conf.CurrentConf.NotificationsReceived += newlyAdded.Count;
            }
            catch (Exception ex)
            {
                Conf.Log($"notification listener failed: {ex.Message}, HRESULT {ex.HResult:x}", LogLevel.Error);
                if (ex.HResult == -2147024891)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await NoPermissionDialog(); });
                }
            }
        }
Exemple #2
0
        private async void OnNotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
        {
            if (args.ChangeKind == UserNotificationChangedKind.Added)
            {
                var notification = await _mediator.Send(new QueryNotificationRequest { Id = args.UserNotificationId });

                if (notification != null)
                {
                    var eventArgs = new NotificationEventArgs {
                        Notification = notification
                    };
                    foreach (var notificationHandler in _notificationHandlers.ToList())
                    {
                        if (eventArgs.Handled)
                        {
                            break;
                        }
                        notificationHandler.OnHandleChatHeadNotification(eventArgs);
                    }
                }
            }
        }
 private void NotificationListener_NotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
 {
     switch (args.ChangeKind)
     {
     case UserNotificationChangedKind.Added:
         UserNotification notification = sender.GetNotification(args.UserNotificationId);
         try
         {
             if (notification != null && notification.AppInfo.AppUserModelId == WINDOWS_SYSTEM_TOAST_CALLING)
             {
                 sender.RemoveNotification(notification.Id);
             }
         }
         catch
         {
         }
         break;
     }
 }
Exemple #4
0
        private async void Listener_NotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
        {
            IReadOnlyList <UserNotification> notifs = await sender.GetNotificationsAsync(NotificationKinds.Toast);

            Debug.WriteLine("--------------NEW Event Received----------------");
            foreach (var notif in notifs)
            {
                NotificationBinding toastBinding = notif.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
                if (toastBinding != null)
                {
                    // And then get the text elements from the toast binding
                    IReadOnlyList <AdaptiveNotificationText> textElements = toastBinding.GetTextElements();

                    // Treat the first text element as the title text
                    string titleText = textElements.FirstOrDefault()?.Text;

                    // We'll treat all subsequent text elements as body text,
                    // joining them together via newlines.
                    string bodyText = string.Join("\n", textElements.Skip(1).Select(t => t.Text));

                    string payload = "App: " + notif.AppInfo.DisplayInfo.DisplayName + " => Title: " + titleText + ", Body: " + bodyText;
                    Debug.WriteLine(payload);
                    _listItems.Add(new NotificationCenterData()
                    {
                        AppName = notif.AppInfo.DisplayInfo.DisplayName,
                        Title   = titleText,
                        Body    = bodyText
                    });
                }
            }
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                NotificationListView.ItemsSource = _listItems;
            });
        }
Exemple #5
0
        private async void Listener_NotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
        {
            var userNotifications = await listener.GetNotificationsAsync(NotificationKinds.Toast);

            foreach (UserNotification userNotification in userNotifications)
            {
                if (userNotification.Id == args.UserNotificationId)
                {
                    var waNotification = new WaNotification(userNotification);

                    ConsoleProxy.WriteLine(null, ConsoleColor.Yellow, $"Notification arrived " +
                                           $"at: {DateTime.Now.ToLocalTime().ToShortTimeString()}, id: {args.UserNotificationId}");
                    if (Helpers.IsValid(waNotification))
                    {
                        var passed = await ProcessNotification(waNotification);

                        if (passed)
                        {
                            listener.RemoveNotification(userNotification.Id);
                        }
                    }
                }
            }
        }