Skip to content

Commit 5ff230b

Browse files
authored
Fix: Fixed closing app when the item flyout is open to hang (#11310)
1 parent af953be commit 5ff230b

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

src/Files.App/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Microsoft.Extensions.DependencyInjection;
3030
using Microsoft.UI.Windowing;
3131
using Microsoft.UI.Xaml;
32+
using Microsoft.UI.Xaml.Controls;
3233
using Microsoft.Windows.AppLifecycle;
3334
using System;
3435
using System.Diagnostics;
@@ -53,6 +54,7 @@ public partial class App : Application
5354
private static bool ShowErrorNotification = false;
5455

5556
public static string OutputPath { get; set; }
57+
public static CommandBarFlyout? LastOpenedFlyout { get; set; }
5658
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper();
5759
public static SettingsViewModel AppSettings { get; private set; }
5860
public static AppModel AppModel { get; private set; }
@@ -286,6 +288,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
286288
{
287289
// Save application state and stop any background activity
288290

291+
// A Workaround for the crash (#10110)
292+
if (LastOpenedFlyout?.IsOpen ?? false)
293+
{
294+
args.Handled = true;
295+
LastOpenedFlyout.Closed += (sender, e) => App.Current.Exit();
296+
LastOpenedFlyout.Hide();
297+
return;
298+
}
299+
289300
await Task.Yield(); // Method can take a long time, make sure the window is hidden
290301

291302
SaveSessionTabs();

src/Files.App/BaseLayout.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
556556

557557
public async void ItemContextFlyout_Opening(object? sender, object e)
558558
{
559+
App.LastOpenedFlyout = sender as CommandBarFlyout;
560+
559561
try
560562
{
561563
if (!IsItemSelected && ((sender as CommandBarFlyout)?.Target as ListViewItem)?.Content is ListedItem li) // Workaround for item sometimes not getting selected
@@ -574,6 +576,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)
574576

575577
public async void BaseContextFlyout_Opening(object? sender, object e)
576578
{
579+
App.LastOpenedFlyout = sender as CommandBarFlyout;
580+
577581
try
578582
{
579583
// Reset menu max height

src/Files.App/UserControls/SidebarControl.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e)
420420
private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
421421
{
422422
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
423+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
423424
if (sender is not NavigationViewItem sidebarItem ||
424425
sidebarItem.DataContext is not INavigationControlItem item)
425426
return;

src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private async void FileTagItem_ItemClick(object sender, ItemClickEventArgs e)
6363
private void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)
6464
{
6565
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
66+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
6667
if (sender is not StackPanel tagsItemsStackPanel || tagsItemsStackPanel.DataContext is not FileTagsItemViewModel item)
6768
return;
6869
itemContextMenuFlyout.ShowAt(tagsItemsStackPanel, new FlyoutShowOptions { Position = e.GetPosition(tagsItemsStackPanel) });

src/Files.App/UserControls/Widgets/HomePageWidget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public abstract class HomePageWidget : UserControl
3636
public void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
3737
{
3838
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
39+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
3940
if (sender is not Button widgetCardItem || widgetCardItem.DataContext is not WidgetCardItem item)
4041
return;
4142

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public RecentFilesWidget()
103103
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
104104
{
105105
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
106+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
106107
if (sender is not Grid recentItemsGrid || recentItemsGrid.DataContext is not RecentItem item)
107108
return;
108109

0 commit comments

Comments
 (0)