2024-11-14 12:37:08 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Media.Animation;
|
|
|
|
|
using System.Windows.Threading;
|
2024-04-25 12:51:43 -03:00
|
|
|
|
|
|
|
|
|
namespace GTPCorrgir
|
|
|
|
|
{
|
|
|
|
|
public partial class notificacion : Window
|
|
|
|
|
{
|
2024-11-14 12:37:08 -03:00
|
|
|
|
private readonly DispatcherTimer autoCloseTimer;
|
|
|
|
|
private readonly DispatcherTimer progressTimer;
|
|
|
|
|
private double progressValue = 0;
|
|
|
|
|
private const int AUTO_CLOSE_SECONDS = 5;
|
|
|
|
|
private const int PROGRESS_UPDATE_INTERVAL = 50; // milisegundos
|
|
|
|
|
|
2024-04-25 12:51:43 -03:00
|
|
|
|
public notificacion()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
PositionWindow();
|
2024-11-14 12:37:08 -03:00
|
|
|
|
|
|
|
|
|
// Configurar el timer para auto-cierre
|
|
|
|
|
autoCloseTimer = new DispatcherTimer
|
|
|
|
|
{
|
|
|
|
|
Interval = TimeSpan.FromSeconds(AUTO_CLOSE_SECONDS)
|
|
|
|
|
};
|
|
|
|
|
autoCloseTimer.Tick += AutoCloseTimer_Tick;
|
|
|
|
|
|
|
|
|
|
// Configurar el timer para la barra de progreso
|
|
|
|
|
progressTimer = new DispatcherTimer
|
|
|
|
|
{
|
|
|
|
|
Interval = TimeSpan.FromMilliseconds(PROGRESS_UPDATE_INTERVAL)
|
|
|
|
|
};
|
|
|
|
|
progressTimer.Tick += ProgressTimer_Tick;
|
|
|
|
|
|
|
|
|
|
// Iniciar animación de entrada
|
|
|
|
|
Loaded += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
var storyboard = (Storyboard)FindResource("FadeIn");
|
|
|
|
|
storyboard.Begin(this);
|
|
|
|
|
autoCloseTimer.Start();
|
|
|
|
|
progressTimer.Start();
|
|
|
|
|
};
|
2024-04-25 12:51:43 -03:00
|
|
|
|
}
|
2024-07-15 09:08:37 -03:00
|
|
|
|
|
2024-04-25 12:51:43 -03:00
|
|
|
|
private void PositionWindow()
|
|
|
|
|
{
|
|
|
|
|
var cursorPosition = System.Windows.Forms.Cursor.Position;
|
2024-07-15 09:08:37 -03:00
|
|
|
|
var screen = System.Windows.Forms.Screen.FromPoint(cursorPosition);
|
2024-04-25 12:51:43 -03:00
|
|
|
|
|
2024-11-14 12:37:08 -03:00
|
|
|
|
this.Left = screen.WorkingArea.Right - this.Width - 20;
|
|
|
|
|
this.Top = screen.WorkingArea.Bottom - this.Height - 20;
|
2024-04-25 12:51:43 -03:00
|
|
|
|
}
|
2024-07-15 09:08:37 -03:00
|
|
|
|
|
2024-04-25 12:51:43 -03:00
|
|
|
|
public void UpdateNotification(string title, string message)
|
|
|
|
|
{
|
|
|
|
|
TitleText.Text = title;
|
|
|
|
|
MessageText.Text = message;
|
2024-11-14 12:37:08 -03:00
|
|
|
|
|
|
|
|
|
// Reiniciar timers y progreso
|
|
|
|
|
progressValue = 0;
|
|
|
|
|
AutoCloseProgress.Value = 0;
|
|
|
|
|
|
|
|
|
|
autoCloseTimer.Stop();
|
|
|
|
|
progressTimer.Stop();
|
|
|
|
|
|
|
|
|
|
autoCloseTimer.Start();
|
|
|
|
|
progressTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void AutoCloseTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
autoCloseTimer.Stop();
|
|
|
|
|
progressTimer.Stop();
|
|
|
|
|
|
|
|
|
|
var storyboard = (Storyboard)FindResource("FadeOut");
|
|
|
|
|
storyboard.Completed += (s, _) => Close();
|
|
|
|
|
storyboard.Begin(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProgressTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
progressValue += (PROGRESS_UPDATE_INTERVAL / (AUTO_CLOSE_SECONDS * 1000.0)) * 100;
|
|
|
|
|
AutoCloseProgress.Value = progressValue;
|
|
|
|
|
|
|
|
|
|
if (progressValue >= 100)
|
|
|
|
|
{
|
|
|
|
|
progressTimer.Stop();
|
|
|
|
|
}
|
2024-04-25 12:51:43 -03:00
|
|
|
|
}
|
2024-07-15 09:08:37 -03:00
|
|
|
|
|
|
|
|
|
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-11-14 12:37:08 -03:00
|
|
|
|
autoCloseTimer.Stop();
|
|
|
|
|
progressTimer.Stop();
|
|
|
|
|
var storyboard = (Storyboard)FindResource("FadeOut");
|
|
|
|
|
storyboard.Completed += (s, _) => Close();
|
|
|
|
|
storyboard.Begin(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseEnter(e);
|
|
|
|
|
autoCloseTimer.Stop();
|
|
|
|
|
progressTimer.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
autoCloseTimer.Start();
|
|
|
|
|
progressTimer.Start();
|
2024-07-15 09:08:37 -03:00
|
|
|
|
}
|
2024-04-25 12:51:43 -03:00
|
|
|
|
}
|
2024-11-14 12:37:08 -03:00
|
|
|
|
}
|