diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ae447ec3..a4337f07d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 5.11.0-alpha.3 ### Features @@ -109,7 +109,6 @@ ### Fixes - Work around iOS SHA1 bug ([#4143](https://github.com/getsentry/sentry-dotnet/pull/4143)) -- Prevent Auto Breadcrumbs Event Binder from leaking and rebinding events ([#4159](https://github.com/getsentry/sentry-dotnet/pull/4159)) - Fixes build error when building .NET Framework applications using Sentry 5.6.0: `MSB4185 :The function "IsWindows" on type "System.OperatingSystem" is not available` ([#4160](https://github.com/getsentry/sentry-dotnet/pull/4160)) - Added a `SentrySetCommitReleaseOptions` build property that can be specified separately from `SentryReleaseOptions` ([#4109](https://github.com/getsentry/sentry-dotnet/pull/4109)) diff --git a/Directory.Build.props b/Directory.Build.props index b5cdf261b8..edb5f629b9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 5.11.0-alpha.1 + 5.11.0-alpha.3 13 true true diff --git a/src/Sentry.Maui/Internal/MauiEventsBinder.cs b/src/Sentry.Maui/Internal/MauiEventsBinder.cs index dd35058015..dbd297ae27 100644 --- a/src/Sentry.Maui/Internal/MauiEventsBinder.cs +++ b/src/Sentry.Maui/Internal/MauiEventsBinder.cs @@ -34,9 +34,6 @@ public MauiEventsBinder(IHub hub, IOptions options, IEnumerab public void HandleApplicationEvents(Application application, bool bind = true) { - // we always unbind first to ensure no previous hooks - UnbindApplication(application); - if (bind) { // Attach element events to all existing descendants (skip the application itself) @@ -68,23 +65,22 @@ public void HandleApplicationEvents(Application application, bool bind = true) // https://docs.microsoft.com/dotnet/maui/user-interface/system-theme-changes#react-to-theme-changes application.RequestedThemeChanged += OnApplicationOnRequestedThemeChanged; } - } - - private void UnbindApplication(Application application) - { - application.DescendantAdded -= OnApplicationOnDescendantAdded; - application.DescendantRemoved -= OnApplicationOnDescendantRemoved; + else + { + application.DescendantAdded -= OnApplicationOnDescendantAdded; + application.DescendantRemoved -= OnApplicationOnDescendantRemoved; - HandleElementEvents(application, bind: false); + HandleElementEvents(application, bind: false); - // Navigation events - application.PageAppearing -= OnApplicationOnPageAppearing; - application.PageDisappearing -= OnApplicationOnPageDisappearing; - application.ModalPushed -= OnApplicationOnModalPushed; - application.ModalPopped -= OnApplicationOnModalPopped; + // Navigation events + application.PageAppearing -= OnApplicationOnPageAppearing; + application.PageDisappearing -= OnApplicationOnPageDisappearing; + application.ModalPushed -= OnApplicationOnModalPushed; + application.ModalPopped -= OnApplicationOnModalPopped; - // Theme changed event - application.RequestedThemeChanged -= OnApplicationOnRequestedThemeChanged; + // Theme changed event + application.RequestedThemeChanged -= OnApplicationOnRequestedThemeChanged; + } } internal void OnApplicationOnDescendantAdded(object? _, ElementEventArgs e) @@ -173,7 +169,6 @@ internal void OnApplicationOnDescendantRemoved(object? _, ElementEventArgs e) internal void HandleWindowEvents(Window window, bool bind = true) { - UnhookWindow(window); if (bind) { // Lifecycle Events @@ -197,39 +192,29 @@ internal void HandleWindowEvents(Window window, bool bind = true) window.ModalPopped += OnWindowOnModalPopped; window.PopCanceled += OnWindowOnPopCanceled; } - } + else + { + // Lifecycle events caused by user action + window.Activated -= OnWindowOnActivated; + window.Deactivated -= OnWindowOnDeactivated; + window.Stopped -= OnWindowOnStopped; + window.Resumed -= OnWindowOnResumed; - private void UnhookWindow(Window window) - { - // Lifecycle events caused by user action - window.Activated -= OnWindowOnActivated; - window.Deactivated -= OnWindowOnDeactivated; - window.Stopped -= OnWindowOnStopped; - window.Resumed -= OnWindowOnResumed; - - // System generated lifecycle events - window.Created -= OnWindowOnCreated; - window.Destroying -= OnWindowOnDestroying; - window.Backgrounding -= OnWindowOnBackgrounding; - window.DisplayDensityChanged -= OnWindowOnDisplayDensityChanged; - - // Navigation events - window.ModalPushed -= OnWindowOnModalPushed; - window.ModalPopped -= OnWindowOnModalPopped; - window.PopCanceled -= OnWindowOnPopCanceled; + // System generated lifecycle events + window.Created -= OnWindowOnCreated; + window.Destroying -= OnWindowOnDestroying; + window.Backgrounding -= OnWindowOnBackgrounding; + window.DisplayDensityChanged -= OnWindowOnDisplayDensityChanged; + + // Navigation events + window.ModalPushed -= OnWindowOnModalPushed; + window.ModalPopped -= OnWindowOnModalPopped; + window.PopCanceled -= OnWindowOnPopCanceled; + } } internal void HandleElementEvents(Element element, bool bind = true) { - // we always unbind the element first to ensure we don't have any sticky or repeat hooks - // Rendering events - element.ChildAdded -= OnElementOnChildAdded; - element.ChildRemoved -= OnElementOnChildRemoved; - element.ParentChanged -= OnElementOnParentChanged; - - // BindableObject events - element.BindingContextChanged -= OnElementOnBindingContextChanged; - if (bind) { // Rendering events @@ -244,30 +229,34 @@ internal void HandleElementEvents(Element element, bool bind = true) // BindableObject events element.BindingContextChanged += OnElementOnBindingContextChanged; } + else + { + // Rendering events + element.ChildAdded -= OnElementOnChildAdded; + element.ChildRemoved -= OnElementOnChildRemoved; + element.ParentChanged -= OnElementOnParentChanged; + + // BindableObject events + element.BindingContextChanged -= OnElementOnBindingContextChanged; + } } internal void HandleVisualElementEvents(VisualElement element, bool bind = true) { - element.Focused -= OnElementOnFocused; - element.Unfocused -= OnElementOnUnfocused; - if (bind) { element.Focused += OnElementOnFocused; element.Unfocused += OnElementOnUnfocused; } + else + { + element.Focused -= OnElementOnFocused; + element.Unfocused -= OnElementOnUnfocused; + } } internal void HandleShellEvents(Shell shell, bool bind = true) { - // Navigation events - // https://docs.microsoft.com/dotnet/maui/fundamentals/shell/navigation - shell.Navigating -= OnShellOnNavigating; - shell.Navigated -= OnShellOnNavigated; - - // A Shell is also a Page - HandlePageEvents(shell, bind: false); - if (bind) { // Navigation events @@ -278,23 +267,20 @@ internal void HandleShellEvents(Shell shell, bool bind = true) // A Shell is also a Page HandlePageEvents(shell); } + else + { + // Navigation events + // https://docs.microsoft.com/dotnet/maui/fundamentals/shell/navigation + shell.Navigating -= OnShellOnNavigating; + shell.Navigated -= OnShellOnNavigated; + + // A Shell is also a Page + HandlePageEvents(shell, bind: false); + } } internal void HandlePageEvents(Page page, bool bind = true) { - // Lifecycle events - // https://docs.microsoft.com/dotnet/maui/fundamentals/shell/lifecycle - page.Appearing -= OnPageOnAppearing; - page.Disappearing -= OnPageOnDisappearing; - - // Navigation events - // https://github.com/dotnet/docs-maui/issues/583 - page.NavigatedTo -= OnPageOnNavigatedTo; - - // Layout changed event - // https://docs.microsoft.com/dotnet/api/xamarin.forms.ilayout.layoutchanged - page.LayoutChanged -= OnPageOnLayoutChanged; - if (bind) { // Lifecycle events @@ -310,6 +296,21 @@ internal void HandlePageEvents(Page page, bool bind = true) // https://docs.microsoft.com/dotnet/api/xamarin.forms.ilayout.layoutchanged page.LayoutChanged += OnPageOnLayoutChanged; } + else + { + // Lifecycle events + // https://docs.microsoft.com/dotnet/maui/fundamentals/shell/lifecycle + page.Appearing -= OnPageOnAppearing; + page.Disappearing -= OnPageOnDisappearing; + + // Navigation events + // https://github.com/dotnet/docs-maui/issues/583 + page.NavigatedTo -= OnPageOnNavigatedTo; + + // Layout changed event + // https://docs.microsoft.com/dotnet/api/xamarin.forms.ilayout.layoutchanged + page.LayoutChanged -= OnPageOnLayoutChanged; + } } // Application Events