Skip to content

Fix Windows Snackbar Registration #2755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ne0rrmatrix
Copy link
Contributor

Description of Change

Fixes a bug where you open and close multiple secondary windows in a Windows environment and have snackbar registered. This prevents the crash that occurs otherwise. This changes the check for Application.Current.Windows.Count from 1 to 0 in OnClosed method for builder Configuration lifecycle events.

Linked Issues

PR Checklist

Additional information

There was a previous attempt to fix this but it set window count to unregister at 1 and not zero. After verifying that when app exits it does call LifeCycle events for OnClosed during shutdown when Application.Current is not null and windows count is zero I created this PR to address the issue.

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 20:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the Windows snackbar registration logic by adjusting the check for the number of windows open during the application shutdown.

  • Changed the condition from checking for 1 open window to checking for 0 open windows in the OnClosed method.
  • Ensures that notifications are unregistered only when there are no open windows, preventing crashes during app shutdown.
Comments suppressed due to low confidence (1)

src/CommunityToolkit.Maui/Options.cs:90

  • The condition has been correctly updated from a check against 1 to 0, which should ensure that snackbar notifications are unregistered only when no windows remain. Please verify that this logic aligns with the overall lifecycle management of window events during app shutdown.
						else if (Application.Current.Windows.Count is 0)

Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ne0rrmatrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Crash on second window close when SnackBar enabled on Windows (still reproducible in v12.0.0)
2 participants