133 lines
4.3 KiB
C#
133 lines
4.3 KiB
C#
using System.Configuration;
|
|
using System.Data;
|
|
using System.Windows;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Forms; // Necesitas agregar una referencia a System.Windows.Forms
|
|
using Application = System.Windows.Application;
|
|
using System.Diagnostics; // Asegúrate de incluir esta directiva para usar Stopwatch
|
|
using System.Threading.Tasks;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace GTPCorrgir
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class App : Application
|
|
{
|
|
gtpask GTP = new gtpask();
|
|
NotifyIcon notificacion;
|
|
System.Windows.Forms.Timer timer;
|
|
bool CorreccionFinalizada = false;
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
private notificacion notificationWindow;
|
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
base.OnStartup(e);
|
|
|
|
stopwatch.Start();
|
|
|
|
if (System.Windows.Clipboard.ContainsText())
|
|
{
|
|
GTP.TextoACorregir = System.Windows.Clipboard.GetText();
|
|
}
|
|
|
|
// Muestra notificación inicial y comienza el cronómetro en el hilo de la UI
|
|
ShowCustomNotification("Espera", "Corrigiendo texto...");
|
|
IniciarCronometro();
|
|
|
|
|
|
// Ejecuta la tarea de corrección en un hilo secundario
|
|
Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
await GTP.CorregirTexto();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error durante la corrección de texto: " + ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
Dispatcher.Invoke(async () => // Nota el 'async' aquí para permitir 'await'
|
|
{
|
|
CorreccionFinalizada = true;
|
|
DetenerCronometro();
|
|
if (GTP.TextoCorregido != null)
|
|
{
|
|
System.Windows.Clipboard.SetText(GTP.TextoCorregido);
|
|
ShowCustomNotification("Se puede pegar", $"Corrección en : {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s");
|
|
|
|
var resultadoWindow = new VentanaResultado(GTP.TextoCorregido);
|
|
resultadoWindow.Show();
|
|
|
|
await Task.Delay(5000); // Asíncrono espera 5 segundos
|
|
}
|
|
else
|
|
{
|
|
MostrarNotificacion("Error", "No se pudo corregir el texto.");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void ShowCustomNotification(string title, string message)
|
|
{
|
|
if (notificationWindow == null)
|
|
{
|
|
notificationWindow = new notificacion();
|
|
notificationWindow.Show();
|
|
}
|
|
|
|
notificationWindow.UpdateNotification(title, message);
|
|
}
|
|
|
|
private void MostrarNotificacion(string titulo, string mensaje)
|
|
{
|
|
notificacion = new NotifyIcon
|
|
{
|
|
Icon = SystemIcons.Information,
|
|
BalloonTipTitle = titulo,
|
|
BalloonTipText = mensaje,
|
|
Visible = true
|
|
};
|
|
notificacion.ShowBalloonTip(1000);
|
|
}
|
|
|
|
|
|
private void IniciarCronometro()
|
|
{
|
|
timer = new System.Windows.Forms.Timer();
|
|
timer.Interval = 100; // 1000 milisegundos (1 segundo)
|
|
timer.Tick += ActualizarCronometro;
|
|
timer.Start();
|
|
}
|
|
|
|
private void ActualizarCronometro(object sender, EventArgs e)
|
|
{
|
|
if (!CorreccionFinalizada) {
|
|
//notificacion.BalloonTipText = $"Texto en {GTP.IdiomaDetectado} pasados: {Math.Round(stopwatch.ElapsedMilliseconds/1000.0,1)} s";
|
|
//notificacion.ShowBalloonTip(1000);
|
|
ShowCustomNotification("Trabajando..", $"Texto en {GTP.IdiomaDetectado} pasados: {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s");
|
|
}
|
|
}
|
|
|
|
private void DetenerCronometro()
|
|
{
|
|
timer.Stop();
|
|
timer.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
}
|