From da3a6591304e50b6129e08a35fb142e71653867c Mon Sep 17 00:00:00 2001 From: nek0der Date: Sun, 25 Jan 2026 12:17:31 +0900 Subject: [PATCH] Fix: Prevent multiple settings windows from opening - Check App.Windows for existing SettingsWindow before creating new one - Use LINQ FirstOrDefault to find open settings window - Activate existing window instead of creating duplicate - Remove need for instance field and event handler cleanup - Follow single source of truth pattern with App.Windows collection --- MainWindow.xaml.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 5ef52e7..e48147e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Drawing; using System.Drawing.Drawing2D; +using System.Linq; using System.Runtime.InteropServices; using CodexBarWin.Models; using CodexBarWin.Services; @@ -234,6 +235,15 @@ private void OnFrameNavigated(object sender, Microsoft.UI.Xaml.Navigation.Naviga private void OnSettingsRequested(object? sender, EventArgs e) { + // Check if settings window is already open + var existingWindow = App.Windows.OfType().FirstOrDefault(); + if (existingWindow != null) + { + existingWindow.Activate(); + return; + } + + // Create and show new settings window var settingsWindow = new SettingsWindow(); settingsWindow.Activate(); }