diff --git a/App.xaml.cs b/App.xaml.cs index 1d4c64b..981620c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,19 +1,30 @@ -using System.Configuration; -using System.Data; +using System; +using System.Threading; using System.Windows; using Application = System.Windows.Application; namespace EscribePassword { - /// - /// Interaction logic for App.xaml - /// public partial class App : Application { + private static Mutex _mutex = null; + public KeyboardHelper PasteLogic { get; } = new KeyboardHelper(); protected override void OnStartup(StartupEventArgs e) { + 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; + } + base.OnStartup(e); PasteLogic.SaveCurrentWindow(); SetInitialWindowPosition(); @@ -26,18 +37,12 @@ namespace EscribePassword if (mainWindow != null) { - - // Obtener la posición del cursor var cursorPosition = System.Windows.Forms.Cursor.Position; - - // Determinar en qué pantalla está el cursor var screen = Screen.FromPoint(cursorPosition); - // Determinar la posición inicial double newLeft = screenRect.Right; double newTop = screenRect.Top; - // Verificar si la ventana se posiciona fuera de la pantalla y ajustarla si es necesario if (newLeft < screenRect.Left) { newLeft = screenRect.Left; @@ -48,11 +53,9 @@ namespace EscribePassword newLeft = screen.WorkingArea.Right - mainWindow.Width; } - // Aplicar la nueva posición mainWindow.Left = newLeft; mainWindow.Top = newTop; } } } - } diff --git a/EscribePassword.csproj b/EscribePassword.csproj index 8460c40..b81735f 100644 --- a/EscribePassword.csproj +++ b/EscribePassword.csproj @@ -13,6 +13,7 @@ + diff --git a/KeyboardHelper.cs b/KeyboardHelper.cs index 59581aa..2f66879 100644 --- a/KeyboardHelper.cs +++ b/KeyboardHelper.cs @@ -2,7 +2,6 @@ using WindowsInput.Native; using WindowsInput; using System.Windows; -using EscribePassword; using CommunityToolkit.Mvvm.ComponentModel; namespace EscribePassword @@ -15,6 +14,10 @@ namespace EscribePassword [ObservableProperty] private string password; + + [ObservableProperty] + private string categoria; + } public class KeyboardHelper diff --git a/MainWindow.xaml b/MainWindow.xaml index 88c7933..63169ea 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -3,7 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:EscribePassword" mc:Ignorable="d" Title="MainWindow" Height="450" Width="300" - AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown"> + AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown" Topmost="True"> @@ -12,30 +12,56 @@ - - - - - - - - -