2024-06-15 19:27:11 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2024-06-15 06:24:07 -03:00
|
|
|
|
using System.Windows;
|
2024-06-15 14:33:52 -03:00
|
|
|
|
using Application = System.Windows.Application;
|
2024-06-15 06:24:07 -03:00
|
|
|
|
|
|
|
|
|
namespace EscribePassword
|
|
|
|
|
{
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
2024-06-15 19:27:11 -03:00
|
|
|
|
private static Mutex _mutex = null;
|
|
|
|
|
|
2024-06-15 14:33:52 -03:00
|
|
|
|
public KeyboardHelper PasteLogic { get; } = new KeyboardHelper();
|
|
|
|
|
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
{
|
2024-06-15 19:27:11 -03:00
|
|
|
|
const string appName = "EscribePasswordApp";
|
|
|
|
|
bool createdNew;
|
|
|
|
|
|
|
|
|
|
_mutex = new Mutex(true, appName, out createdNew);
|
|
|
|
|
|
|
|
|
|
if (!createdNew)
|
|
|
|
|
{
|
|
|
|
|
// Hay otra instancia en ejecución, cerramos esta instancia
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 14:33:52 -03:00
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
PasteLogic.SaveCurrentWindow();
|
|
|
|
|
SetInitialWindowPosition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetInitialWindowPosition()
|
|
|
|
|
{
|
|
|
|
|
var screenRect = PasteLogic.GetScreenOfPreviousWindow();
|
|
|
|
|
var mainWindow = Application.Current.MainWindow;
|
|
|
|
|
|
|
|
|
|
if (mainWindow != null)
|
|
|
|
|
{
|
|
|
|
|
var cursorPosition = System.Windows.Forms.Cursor.Position;
|
|
|
|
|
var screen = Screen.FromPoint(cursorPosition);
|
|
|
|
|
|
|
|
|
|
double newLeft = screenRect.Right;
|
|
|
|
|
double newTop = screenRect.Top;
|
|
|
|
|
|
|
|
|
|
if (newLeft < screenRect.Left)
|
|
|
|
|
{
|
|
|
|
|
newLeft = screenRect.Left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newLeft + mainWindow.Width > screen.WorkingArea.Right)
|
|
|
|
|
{
|
|
|
|
|
newLeft = screen.WorkingArea.Right - mainWindow.Width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mainWindow.Left = newLeft;
|
|
|
|
|
mainWindow.Top = newTop;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 06:24:07 -03:00
|
|
|
|
}
|
|
|
|
|
}
|