예제 #1
0
        public void PopupNotification(OverlayNotification notification)
        {
            if (Settings.Default.EnableOverlay)
                try
                {
                    Dispatcher.Invoke(() =>
                    {
                        if (notification.UniqueID != null &&
                            StackNotifications.GetChildObjects()
                                .Any(
                                    toast => (toast as OverlayToast)?.BaseNotification.UniqueID == notification.UniqueID))
                            return;
                        var popupNotification = new OverlayToast(notification);
                        popupNotification.NotificationCompleted += (sender, args) =>
                        {
                            StackNotifications.Children.Remove(popupNotification);
                            popupNotification = null;
                        };
                        StackNotifications.Children.Add(popupNotification);
                    });
                }
                catch (ThreadAbortException)
                {

                }
                catch (Exception ex)
                {
                    Log.WriteLine($"Exception occured during popup creation: {ex.Message}");
                }
        }
예제 #2
0
        public OverlayToast(OverlayNotification notification)
        {
            BaseNotification = notification;
            _duration = notification.Duration;
            _fadeIn = notification.FadeIn;
            _fadeOut = notification.FadeOut;

            InitializeComponent();
            if (notification.Image != null)
            {
                ImageIcon.Source = notification.Image;
            }
            else
            {
                ImageIcon.Source = OverlayIcons.Random();
            }

            NotificationHeader.Text = notification.Header;
            NotificationText.Text = notification.Content;
            UpdateLayout();
            Dispatcher.Invoke(FadeIn);
            new Thread(() =>
            {
                Thread.Sleep(_duration);
                try
                {
                    Dispatcher.Invoke(FadeOut);
                } catch { }
            }).Start();
        }
예제 #3
0
        public void PopupNotification(OverlayNotification notification)
        {
            if (!IsRunning) return;

            Log.WriteLine($"Show notification: {notification.Header}: {notification.Content}");
            _overlay.PopupNotification(notification);
        }
예제 #4
0
 // Create an overlay, draw a rectangle on the overlay to cap that area
 public void CaptureArea()
 {
     if (!overlay_created)
     {
         //var foregroundWindow = NativeMethods.GetForegroundWindow();
         overlay_created = true;
         OverlayNotification notification = new OverlayNotification()
         {
             Title        = "Overlay",
             WindowTop    = SystemParameters.VirtualScreenTop,
             WindowLeft   = SystemParameters.VirtualScreenLeft,
             WindowWidth  = SystemParameters.VirtualScreenWidth,
             WindowHeight = SystemParameters.VirtualScreenHeight
         };
         this.OverlayRequest.Raise(
             notification, returned =>
         {
             if (returned != null && returned.Confirmed)
             {
                 // get dpi multiplier
                 Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
                 //var works = NativeMethods.SetForegroundWindow(foregroundWindow);
                 //Console.WriteLine(works);
                 SaveAndUploadImage(
                     EncodeImage(
                         ScreenCapture.CaptureArea(Convert.ToInt32(notification.Rect.Width * m.M22),
                                                   Convert.ToInt32(notification.Rect.Height * m.M11),
                                                   Convert.ToInt32(notification.Rect.X * m.M11),
                                                   Convert.ToInt32(notification.Rect.Y * m.M22),
                                                   false)
                         ),
                     "areacapture");
                 SoundPlayer.PlaySound();
             }
             overlay_created = false;
         });
     }
 }