Skip to content

Commit bf1e707

Browse files
Refactor: Close all dialogs asynchronously
1 parent ec7cfdc commit bf1e707

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Files.App/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
234234
!Process.GetProcessesByName("Files").Any(x => x.Id != Environment.ProcessId))
235235
{
236236
// Close open content dialogs
237-
UIHelpers.CloseAllDialogs();
237+
await UIHelpers.CloseAllDialogsAsync();
238238

239239
// Close all notification banners except in progress
240240
statusCenterViewModel.RemoveAllCompletedItems();

src/Files.App/Helpers/UI/UIHelpers.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ public static void CloseAllDialogs()
102102
dialog.Hide();
103103
}
104104

105+
public static async Task CloseAllDialogsAsync()
106+
{
107+
if (MainWindow.Instance?.Content?.XamlRoot == null)
108+
return;
109+
110+
var openedDialogs = VisualTreeHelper.GetOpenPopupsForXamlRoot(MainWindow.Instance.Content.XamlRoot);
111+
var closingTasks = new List<Task>();
112+
foreach (var item in openedDialogs)
113+
{
114+
if (item.Child is ContentDialog dialog)
115+
{
116+
var tcs = new TaskCompletionSource();
117+
dialog.Closed += (s, e) => tcs.SetResult();
118+
dialog.Hide();
119+
closingTasks.Add(tcs.Task);
120+
}
121+
}
122+
await Task.WhenAll(closingTasks);
123+
}
124+
105125
private static IEnumerable<IconFileInfo> SidebarIconResources = LoadSidebarIconResources();
106126

107127
private static IconFileInfo ShieldIconResource = LoadShieldIconResource();

0 commit comments

Comments
 (0)