public void AddNotification(LivestreamNotification livestreamNotification)
        {
            if (settingsHandler.Settings.DisableNotifications)
            {
                return;
            }
            if (livestreamNotification.LivestreamModel.DontNotify)
            {
                return;
            }
            // don't notify for streams that are being watched right now
            if (streamLauncher.WatchingStreams.Contains(livestreamNotification.LivestreamModel))
            {
                return;
            }

            if ((notifications.Count + 1) > MAX_NOTIFICATIONS)
            {
                buffer.Add(livestreamNotification);
            }
            else
            {
                notifications.Add(livestreamNotification);
                ShowNotification(livestreamNotification);
            }
        }
        private void ShowNotification(LivestreamNotification livestreamNotification)
        {
            var vmTopLeft = GetNotificationTopLeft(livestreamNotification);
            var settings  = new WindowSettingsBuilder().NoResizeBorderless()
                            .WithTopLeft(vmTopLeft.Y, vmTopLeft.X)
                            .TransparentBackground()
                            .AsTopmost()
                            .Create();

            var notificationViewModel = new NotificationViewModel(livestreamNotification, monitorStreamsModel);

            // put remaining notifications into their correct position after this LivestreamNotification closes
            notificationViewModel.Deactivated += (sender, args) =>
            {
                AdjustWindows();
                RemoveNotification(notificationViewModel.LivestreamNotification);
            };

            Execute.OnUIThread(() =>
            {
                windowManager.ShowWindow(notificationViewModel, null, settings);

                // Close the popup after a brief duration
                var timer = new DispatcherTimer()
                {
                    Interval = livestreamNotification.Duration
                };
                timer.Tick += (sender, args) =>
                {
                    notificationViewModel.TryClose();
                    timer.Stop();
                };
                timer.Start();
            });
        }
        private void LivestreamOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var livestreamModel = (LivestreamModel)sender;

            if (e.PropertyName == nameof(LivestreamModel.Live) && hasRefreshed) // dont show notifications for the initial refresh
            {
                if (!livestreamModel.Live)
                {
                    return;                        // only care about streams coming online
                }
                // avoid a twitch api bug where sometimes online streams will not be returned when querying for online streams
                // the best way we can work around this is to pick a reasonable uptime value after which we will never show online notifications.
                // we check the LastLiveTime for null to ensure we will always notify the first time a stream come online
                if (livestreamModel.LastLiveTime != null && livestreamModel.Uptime > TimeSpan.FromMinutes(5))
                {
                    return;
                }

                var notification = new LivestreamNotification()
                {
                    Title           = $"{livestreamModel.DisplayName} Online",
                    Message         = livestreamModel.Description,
                    ImageUrl        = livestreamModel.ThumbnailUrls?.Small,
                    LivestreamModel = livestreamModel,
                };

                AddNotification(notification);
            }
        }
Beispiel #4
0
 public NotificationViewModel(
     LivestreamNotification livestreamNotification,
     IMonitorStreamsModel model)
 {
     LivestreamNotification = livestreamNotification ?? throw new ArgumentNullException(nameof(livestreamNotification));
     this.model             = model ?? throw new ArgumentNullException(nameof(model));
 }
 private void RemoveNotification(LivestreamNotification livestreamNotification)
 {
     if (notifications.Contains(livestreamNotification))
     {
         notifications.Remove(livestreamNotification);
     }
     if (buffer.Count > 0)
     {
         AddNotification(buffer[0]);
         buffer.RemoveAt(0);
     }
 }
Beispiel #6
0
        public NotificationViewModel()
        {
            if (!Execute.InDesignMode)
            {
                throw new InvalidOperationException("Constructor only accessible from design time");
            }

            LivestreamNotification = new LivestreamNotification()
            {
                Title   = "Someones stream is online",
                Message = "Livestream description for someones stream"
            };
        }
        private Point GetNotificationTopLeft(LivestreamNotification livestreamNotification)
        {
            if (livestreamNotification == null)
            {
                return(new Point());
            }

            var index = notifications.IndexOf(livestreamNotification) + 1;

            // we care about the order the notifications were added for vertical positioning
            if (index == 0)
            {
                return(new Point());
            }

            return(new Point()
            {
                X = SystemParameters.WorkArea.Right - NotificationViewWindowWidth - RightMargin,
                Y = SystemParameters.WorkArea.Bottom - (NotificationViewWindowHeight * index) - BottomMargin
            });
        }