From 51b54ddedb4243d38ab700b2316249e9aab80f49 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:46:27 -0400 Subject: [PATCH 1/2] Code Quality: Handle WinUI Desktop Window already closed --- src/Files.App/MainWindow.xaml.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 0bd6c7279cbc..73840f0ab03e 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -1,6 +1,7 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. +using Microsoft.Extensions.Logging; using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml.Controls; @@ -247,11 +248,25 @@ async Task PerformNavigationAsync(string payload, string selectItem = null) } var generalSettingsService = Ioc.Default.GetService(); + + double boundsWidth = 0; + try + { + boundsWidth = Bounds.Width; + } + catch (Exception ex) + { + // Handle exception in case WinUI Windows is closed + // (see https://github.com/files-community/Files/issues/15599) + + App.Logger.LogWarning(ex, ex.Message); + } + var paneNavigationArgs = new PaneNavigationArguments { LeftPaneNavPathParam = payload, LeftPaneSelectItemParam = selectItem, - RightPaneNavPathParam = Bounds.Width > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null, + RightPaneNavPathParam = boundsWidth > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null, }; if (rootFrame.Content is MainPage && MainPageViewModel.AppInstances.Any()) From bf8ee7bb830730520152ccb06e8603a3792f6891 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:20:16 -0400 Subject: [PATCH 2/2] Update src/Files.App/MainWindow.xaml.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> --- src/Files.App/MainWindow.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 73840f0ab03e..ce6c08cb6698 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -260,6 +260,7 @@ async Task PerformNavigationAsync(string payload, string selectItem = null) // (see https://github.com/files-community/Files/issues/15599) App.Logger.LogWarning(ex, ex.Message); + return; } var paneNavigationArgs = new PaneNavigationArguments