Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed closing app when the item flyout is open to hang #11310

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -556,6 +556,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)

public async void ItemContextFlyout_Opening(object? sender, object e)
{
App.LastOpenedFlyout = sender as CommandBarFlyout;

try
{
if (!IsItemSelected && ((sender as CommandBarFlyout)?.Target as ListViewItem)?.Content is ListedItem li) // Workaround for item sometimes not getting selected
Expand All @@ -574,6 +576,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)

public async void BaseContextFlyout_Opening(object? sender, object e)
{
App.LastOpenedFlyout = sender as CommandBarFlyout;

try
{
// Reset menu max height
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;
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
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