Skip to content

Fix: Prevent multiple settings windows from opening#11

Closed
nek0der wants to merge 1 commit into
mainfrom
fix/prevent-duplicate-settings-windows
Closed

Fix: Prevent multiple settings windows from opening#11
nek0der wants to merge 1 commit into
mainfrom
fix/prevent-duplicate-settings-windows

Conversation

@nek0der
Copy link
Copy Markdown
Owner

@nek0der nek0der commented Jan 25, 2026

Description

Fixes a bug where clicking the Settings button multiple times would open multiple instances of the settings window, instead of activating the existing one.

Implementation:

  • Uses App.Windows.OfType<SettingsWindow>().FirstOrDefault() to check for existing window
  • Activates existing window instead of creating duplicate
  • Follows single source of truth pattern with App.Windows collection
  • Eliminates need for instance field and event handler cleanup

Benefits:

  • Cleaner code (no instance field, no Closed event handler)
  • Automatic lifecycle management via App.Windows
  • Prevents memory leaks from forgotten event handler cleanup
  • More maintainable and scalable pattern

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Build/CI changes

How Has This Been Tested?

  • Manual testing on Windows x64
  • Manual testing on Windows ARM64
  • Tested with multiple providers (list which ones)

Test Configuration:

  • Windows Version: Windows 11
  • .NET Version: .NET 10.0

Manual Test Steps:

  1. Run the application
  2. Click Settings button from tray context menu or main window
  3. Without closing settings window, click Settings button again
  4. Verify that existing settings window is activated instead of opening a new one

Unit Tests:

  • All 133 existing unit tests pass
  • UI layer (Views) is exempt from unit testing per project conventions

Screenshots (if applicable)

N/A - Behavior fix, no visual changes

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • I have added entries to CHANGELOG.md (if applicable)
  • My changes generate no new warnings
  • I have tested my changes locally
  • Any dependent changes have been merged and published

Breaking Changes

N/A

Additional Notes

Files changed:

  • MainWindow.xaml.cs - Added window existence check before creating new SettingsWindow

Technical details:

  • Added using System.Linq; for LINQ operations
  • Replaced instance field + event handler pattern with query-based approach
  • Leverages existing App.Windows collection managed by SettingsWindow.Closed event

This follows WinUI/WPF best practices for managing multiple window instances.

- 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
@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity.
It will be closed in 14 days if no further activity occurs.
If you're still working on this, please comment or push new commits.

@github-actions github-actions Bot added the stale label Feb 25, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been automatically closed due to inactivity.
Feel free to reopen if you'd like to continue working on this.

@github-actions github-actions Bot closed this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant