Skip to content

Commit 3dd2a8a

Browse files
Refactor: Make CloseAllDialogs async
1 parent ec7cfdc commit 3dd2a8a

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
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.CloseAllDialogs();
238238

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

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,24 @@ private static ContentDialog SetContentDialogRoot(ContentDialog contentDialog)
9090
return contentDialog;
9191
}
9292

93-
public static void CloseAllDialogs()
93+
public static async Task CloseAllDialogs()
9494
{
9595
if (MainWindow.Instance?.Content?.XamlRoot == null)
9696
return;
9797

9898
var openedDialogs = VisualTreeHelper.GetOpenPopupsForXamlRoot(MainWindow.Instance.Content.XamlRoot);
99-
99+
var closingTasks = new List<Task>();
100100
foreach (var item in openedDialogs)
101+
{
101102
if (item.Child is ContentDialog dialog)
103+
{
104+
var tcs = new TaskCompletionSource();
105+
dialog.Closed += (s, e) => tcs.SetResult();
102106
dialog.Hide();
107+
closingTasks.Add(tcs.Task);
108+
}
109+
}
110+
await Task.WhenAll(closingTasks);
103111
}
104112

105113
private static IEnumerable<IconFileInfo> SidebarIconResources = LoadSidebarIconResources();

src/Files.App/Utils/Git/GitHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ public static async Task CloneRepoAsync(string repoUrl, string repoName, string
931931

932932
if (!string.IsNullOrEmpty(errorMessage))
933933
{
934-
UIHelpers.CloseAllDialogs();
934+
await UIHelpers.CloseAllDialogs();
935935
await Task.Delay(500);
936936
await DynamicDialogFactory.ShowFor_CannotCloneRepo(errorMessage);
937937
}

src/Files.App/ViewModels/Settings/AboutViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private async Task<bool> OpenLogLocation()
108108

109109
// Close the settings dialog if Files is the deault file manager
110110
if (!string.IsNullOrEmpty(command) && command.Contains("Files.App.Launcher.exe"))
111-
UIHelpers.CloseAllDialogs();
111+
await UIHelpers.CloseAllDialogs();
112112

113113
return true;
114114
}

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private async Task ImportSettingsAsync()
187187
catch (Exception ex)
188188
{
189189
App.Logger.LogWarning(ex, "Error importing settings");
190-
UIHelpers.CloseAllDialogs();
190+
await UIHelpers.CloseAllDialogs();
191191
await DialogDisplayHelper.ShowDialogAsync(Strings.SettingsImportErrorTitle.GetLocalizedResource(), Strings.SettingsImportErrorDescription.GetLocalizedResource());
192192
}
193193
}

src/Files.App/ViewModels/Settings/DevToolsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void DoRemoveCredentials()
130130

131131
public async void DoConnectToGitHubAsync()
132132
{
133-
UIHelpers.CloseAllDialogs();
133+
await UIHelpers.CloseAllDialogs();
134134

135135
await Task.Delay(500);
136136

0 commit comments

Comments
 (0)