Skip to content

Commit

Permalink
Fixed crash related to CommandBarFlyout
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu committed Feb 15, 2023
1 parent 50a0108 commit 37d7cc0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommunityToolkit.WinUI;
using CommunityToolkit.WinUI.Helpers;
using CommunityToolkit.WinUI.Notifications;
using Files.App.Controllers;
using Files.App.DataModels;
using Files.App.Extensions;
using Files.App.Filesystem;
Expand Down Expand Up @@ -30,6 +29,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppLifecycle;
using System;
using System.Diagnostics;
Expand All @@ -54,6 +54,7 @@ public partial class App : Application
private static bool ShowErrorNotification = false;

public static string OutputPath { get; set; }
public static CommandBarFlyout? LastOpenedFlyout { get; set; }
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper();
public static SettingsViewModel AppSettings { get; private set; }
public static AppModel AppModel { get; private set; }
Expand Down Expand Up @@ -287,6 +288,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
{
// Save application state and stop any background activity

// A Workaround for the crash (#10110)
if (LastOpenedFlyout?.IsOpen ?? false)
{
args.Handled = true;
LastOpenedFlyout.Closed += (sender, e) => App.Current.Exit();
LastOpenedFlyout.Hide();
return;
}

await Task.Yield(); // Method can take a long time, make sure the window is hidden

SaveSessionTabs();
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)

if (IsItemSelected)
await LoadMenuItemsAsync();

App.LastOpenedFlyout = sender as CommandBarFlyout;
}
catch (Exception error)
{
Expand Down Expand Up @@ -607,6 +609,8 @@ public async void BaseContextFlyout_Opening(object? sender, object e)
else
RemoveOverflow(BaseContextMenuFlyout);
}

App.LastOpenedFlyout = sender as CommandBarFlyout;
}
catch (Exception error)
{
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e)
private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not NavigationViewItem sidebarItem ||
sidebarItem.DataContext is not INavigationControlItem item)
return;
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private async void FileTagItem_ItemClick(object sender, ItemClickEventArgs e)
private void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not StackPanel tagsItemsStackPanel || tagsItemsStackPanel.DataContext is not FileTagsItemViewModel item)
return;
itemContextMenuFlyout.ShowAt(tagsItemsStackPanel, new FlyoutShowOptions { Position = e.GetPosition(tagsItemsStackPanel) });
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/UserControls/Widgets/HomePageWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class HomePageWidget : UserControl
public void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not Button widgetCardItem || widgetCardItem.DataContext is not WidgetCardItem item)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public RecentFilesWidget()
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
if (sender is not Grid recentItemsGrid || recentItemsGrid.DataContext is not RecentItem item)
return;

Expand Down

0 comments on commit 37d7cc0

Please sign in to comment.