diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index b4a5c62c88dd..b5010974ff4c 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -4,8 +4,10 @@ using Files.App.UserControls.FilePreviews; using Files.App.ViewModels.Previews; using Files.Shared.Helpers; +using Microsoft.Extensions.Logging; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Sentry; using Windows.Storage; namespace Files.App.ViewModels.UserControls @@ -13,6 +15,7 @@ namespace Files.App.ViewModels.UserControls public sealed class InfoPaneViewModel : ObservableObject, IDisposable { private IInfoPaneSettingsService infoPaneSettingsService { get; } = Ioc.Default.GetRequiredService(); + private IGeneralSettingsService generalSettingsService { get; } = Ioc.Default.GetRequiredService(); private IContentPageContext contentPageContext { get; } = Ioc.Default.GetRequiredService(); private CancellationTokenSource loadCancellationTokenSource; @@ -136,12 +139,29 @@ private async void ContentPageContext_PropertyChanged(object? sender, PropertyCh SelectedItem = tempSelectedItem; - if (!App.AppModel.IsMainWindowClosed) + try { - var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive; - if (shouldUpdatePreview == true) - _ = UpdateSelectedItemPreviewAsync(); + if (!App.AppModel.IsMainWindowClosed) + { + var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive; + if (shouldUpdatePreview == true) + _ = UpdateSelectedItemPreviewAsync(); + } } + catch (Exception ex) + { + // Handle exception in case WinUI Windows is closed + // (see https://github.com/files-community/Files/issues/15599) + + SentrySdk.CaptureException(ex, scope => + { + scope.User.Id = generalSettingsService.UserId; + scope.Level = SentryLevel.Warning; + }); + + App.Logger.LogWarning(ex, ex.Message); + } + break; } } diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 721189e43c88..ca90a28bd088 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -12,6 +12,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Navigation; +using Sentry; using System.Data; using Windows.ApplicationModel; using Windows.ApplicationModel.DataTransfer; @@ -25,6 +26,7 @@ namespace Files.App.Views { public sealed partial class MainPage : Page { + private IGeneralSettingsService generalSettingsService { get; } = Ioc.Default.GetRequiredService(); public IUserSettingsService UserSettingsService { get; } public ICommandManager Commands { get; } @@ -442,16 +444,32 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl private void LoadPaneChanged() { - var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false); - var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false; - var isBigEnough = !App.AppModel.IsMainWindowClosed && - (MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360); + try + { + var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false); + var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false; + var isBigEnough = !App.AppModel.IsMainWindowClosed && + (MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360); + + ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough; + ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed; + ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; + + UpdatePositioning(); + } + catch (Exception ex) + { + // Handle exception in case WinUI Windows is closed + // (see https://github.com/files-community/Files/issues/15599) - ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough; - ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed; - ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; + SentrySdk.CaptureException(ex, scope => + { + scope.User.Id = generalSettingsService.UserId; + scope.Level = SentryLevel.Warning; + }); - UpdatePositioning(); + App.Logger.LogWarning(ex, ex.Message); + } } private async void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)