Skip to content

Commit 09b4d19

Browse files
yaira2hishitetsu
andauthored
Code Quality: Handle WinUI Desktop Window already closed (#15864)
Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
1 parent 2b0a914 commit 09b4d19

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Files.App/MainWindow.xaml.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.Extensions.Logging;
45
using Microsoft.UI;
56
using Microsoft.UI.Windowing;
67
using Microsoft.UI.Xaml.Controls;
@@ -247,11 +248,26 @@ async Task PerformNavigationAsync(string payload, string selectItem = null)
247248
}
248249

249250
var generalSettingsService = Ioc.Default.GetService<IGeneralSettingsService>();
251+
252+
double boundsWidth = 0;
253+
try
254+
{
255+
boundsWidth = Bounds.Width;
256+
}
257+
catch (Exception ex)
258+
{
259+
// Handle exception in case WinUI Windows is closed
260+
// (see https://github.com/files-community/Files/issues/15599)
261+
262+
App.Logger.LogWarning(ex, ex.Message);
263+
return;
264+
}
265+
250266
var paneNavigationArgs = new PaneNavigationArguments
251267
{
252268
LeftPaneNavPathParam = payload,
253269
LeftPaneSelectItemParam = selectItem,
254-
RightPaneNavPathParam = Bounds.Width > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null,
270+
RightPaneNavPathParam = boundsWidth > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null,
255271
};
256272

257273
if (rootFrame.Content is MainPage && MainPageViewModel.AppInstances.Any())

0 commit comments

Comments
 (0)