Example #1
0
        private void NotifyIcon_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (!isLoaded)
            {
                TrayIcon = DataContext as ManagedShell.WindowsTray.NotifyIcon;

                if (TrayIcon == null)
                {
                    return;
                }

                applyEffects();

                TrayIcon.NotificationBalloonShown += TrayIcon_NotificationBalloonShown;

                // If a notification was received before we started listening, it will be here. Show the first one that is not expired.
                NotificationBalloon firstUnexpiredNotification = TrayIcon.MissedNotifications.FirstOrDefault(balloon => balloon.Received.AddMilliseconds(balloon.Timeout) > DateTime.Now);

                if (firstUnexpiredNotification != null && Host != null && Host.Screen.Primary)
                {
                    BalloonControl.Show(firstUnexpiredNotification, NotifyIconBorder);
                    TrayIcon.MissedNotifications.Remove(firstUnexpiredNotification);
                }

                isLoaded = true;
            }
        }
Example #2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (_isLoaded)
            {
                return;
            }

            _notifyIcon = DataContext as NotifyIcon;

            if (_notifyIcon == null)
            {
                return;
            }

            _notifyIcon.NotificationBalloonShown += TrayIcon_NotificationBalloonShown;

            // If a notification was received before we started listening, it will be here. Show the first one that is not expired.
            NotificationBalloon firstUnexpiredNotification = _notifyIcon.MissedNotifications.FirstOrDefault(balloon => balloon.Received.AddMilliseconds(GetAdjustedBalloonTimeout(balloon)) > DateTime.Now);

            if (firstUnexpiredNotification != null)
            {
                showBalloon(firstUnexpiredNotification);
                _notifyIcon.MissedNotifications.Remove(firstUnexpiredNotification);
            }

            _isLoaded = true;
        }
Example #3
0
        private void playSound(NotificationBalloon balloonInfo)
        {
            if ((balloonInfo.Flags & NativeMethods.NIIF.NOSOUND) != 0)
            {
                return;
            }

            SoundHelper.PlayNotificationSound();
        }
Example #4
0
        private void playSound(NotificationBalloon balloonInfo)
        {
            if (BalloonPopup.IsOpen)
            {
                return;
            }

            if ((balloonInfo.Flags & ManagedShell.Interop.NativeMethods.NIIF.NOSOUND) != 0)
            {
                return;
            }

            SoundHelper.PlayNotificationSound();
        }
Example #5
0
        private void showBalloon(NotificationBalloon balloon)
        {
            Balloon = balloon;
            playSound(Balloon);

            _balloonTimer?.Stop();

            _balloonTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(GetAdjustedBalloonTimeout(Balloon))
            };

            _balloonTimer.Tick += BalloonTimer_Tick;
            _balloonTimer.Start();
        }
Example #6
0
        public void Show(NotificationBalloon balloonInfo, UIElement placementTarget)
        {
            _balloonInfo = balloonInfo;
            DataContext  = _balloonInfo;

            playSound(_balloonInfo);

            BalloonPopup.PlacementTarget = placementTarget;
            BalloonPopup.Placement       = PlacementMode.Custom;
            BalloonPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(PlacePopup);
            BalloonPopup.IsOpen = true;

            _balloonInfo.SetVisibility(BalloonVisibility.Visible);

            startTimer(balloonInfo.Timeout);
        }
Example #7
0
        internal static int GetAdjustedBalloonTimeout(NotificationBalloon balloon)
        {
            // valid timeout is 12-30 seconds
            int timeout = balloon.Timeout;

            if (timeout < 12000)
            {
                timeout = 12000;
            }
            else if (timeout > 30000)
            {
                timeout = 30000;
            }

            return(timeout);
        }