From f6d2c8ce7b994bf31029297731d26921b71f8042 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:10:20 -0400 Subject: [PATCH 1/6] Fix: Prevent issue "WinUI Desktop Window object has already been closed" --- .../UserControls/InfoPaneViewModel.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index b4a5c62c88dd..85f721403207 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -6,6 +6,7 @@ using Files.Shared.Helpers; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Sentry; using Windows.Storage; namespace Files.App.ViewModels.UserControls @@ -13,6 +14,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 +138,27 @@ 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; + }); + } + break; } } From 9c115b57ee5a5a05ea033cdd46a72e5dd357a97f Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:14:25 -0400 Subject: [PATCH 2/6] Update MainPage.xaml.cs --- src/Files.App/Views/MainPage.xaml.cs | 32 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 721189e43c88..4048e20946d1 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,14 +444,28 @@ 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); - - ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough; - ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed; - ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; + 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; + } + 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; + }); + } UpdatePositioning(); } From 79e7051e925e1a0369b05bffc3097756e4262f08 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 16 Jun 2024 23:10:25 -0400 Subject: [PATCH 3/6] Log error --- src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs | 3 +++ src/Files.App/Views/MainPage.xaml.cs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index 85f721403207..6e89a68ba336 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -4,6 +4,7 @@ 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; @@ -157,6 +158,8 @@ private async void ContentPageContext_PropertyChanged(object? sender, PropertyCh scope.User.Id = generalSettingsService.UserId; scope.Level = SentryLevel.Warning; }); + + App.Logger.LogError(ex, ex.Message); } break; diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 4048e20946d1..262b46fe44c0 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -465,7 +465,9 @@ private void LoadPaneChanged() scope.User.Id = generalSettingsService.UserId; scope.Level = SentryLevel.Warning; }); - } + + App.Logger.LogError(ex, ex.Message); + } UpdatePositioning(); } From d3f2bbe51dad525a2f8e02db44e7a1b4503fd46d Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 17 Jun 2024 06:57:11 -0700 Subject: [PATCH 4/6] Update src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> --- src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index 6e89a68ba336..b5010974ff4c 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -159,7 +159,7 @@ private async void ContentPageContext_PropertyChanged(object? sender, PropertyCh scope.Level = SentryLevel.Warning; }); - App.Logger.LogError(ex, ex.Message); + App.Logger.LogWarning(ex, ex.Message); } break; From 587b44e79efd6e29bfe9083e9754761b1761e18e Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 17 Jun 2024 06:57:16 -0700 Subject: [PATCH 5/6] Update src/Files.App/Views/MainPage.xaml.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> --- src/Files.App/Views/MainPage.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 262b46fe44c0..552568675d9d 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -466,7 +466,7 @@ private void LoadPaneChanged() scope.Level = SentryLevel.Warning; }); - App.Logger.LogError(ex, ex.Message); + App.Logger.LogWarning(ex, ex.Message); } UpdatePositioning(); From 2e37870ece7a71bb2707c129e411326b69606ca7 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 17 Jun 2024 09:58:38 -0400 Subject: [PATCH 6/6] Update MainPage.xaml.cs --- src/Files.App/Views/MainPage.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 552568675d9d..ca90a28bd088 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -454,6 +454,8 @@ private void LoadPaneChanged() ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough; ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed; ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; + + UpdatePositioning(); } catch (Exception ex) { @@ -468,8 +470,6 @@ private void LoadPaneChanged() App.Logger.LogWarning(ex, ex.Message); } - - UpdatePositioning(); } private async void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)