Skip to content

Refactor: Make CloseAllDialogs async #17364

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
!Process.GetProcessesByName("Files").Any(x => x.Id != Environment.ProcessId))
{
// Close open content dialogs
UIHelpers.CloseAllDialogs();
await UIHelpers.CloseAllDialogs();

// Close all notification banners except in progress
statusCenterViewModel.RemoveAllCompletedItems();
Expand Down
12 changes: 10 additions & 2 deletions src/Files.App/Helpers/UI/UIHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,24 @@ private static ContentDialog SetContentDialogRoot(ContentDialog contentDialog)
return contentDialog;
}

public static void CloseAllDialogs()
public static async Task CloseAllDialogs()
{
if (MainWindow.Instance?.Content?.XamlRoot == null)
return;

var openedDialogs = VisualTreeHelper.GetOpenPopupsForXamlRoot(MainWindow.Instance.Content.XamlRoot);

var closingTasks = new List<Task>();
foreach (var item in openedDialogs)
{
if (item.Child is ContentDialog dialog)
{
var tcs = new TaskCompletionSource();
dialog.Closed += (s, e) => tcs.SetResult();
dialog.Hide();
closingTasks.Add(tcs.Task);
}
}
await Task.WhenAll(closingTasks);
}

private static IEnumerable<IconFileInfo> SidebarIconResources = LoadSidebarIconResources();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Git/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ public static async Task CloneRepoAsync(string repoUrl, string repoName, string

if (!string.IsNullOrEmpty(errorMessage))
{
UIHelpers.CloseAllDialogs();
await UIHelpers.CloseAllDialogs();
await Task.Delay(500);
await DynamicDialogFactory.ShowFor_CannotCloneRepo(errorMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async Task<bool> OpenLogLocation()

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

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private async Task ImportSettingsAsync()
catch (Exception ex)
{
App.Logger.LogWarning(ex, "Error importing settings");
UIHelpers.CloseAllDialogs();
await UIHelpers.CloseAllDialogs();
await DialogDisplayHelper.ShowDialogAsync(Strings.SettingsImportErrorTitle.GetLocalizedResource(), Strings.SettingsImportErrorDescription.GetLocalizedResource());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/DevToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void DoRemoveCredentials()

public async void DoConnectToGitHubAsync()
{
UIHelpers.CloseAllDialogs();
await UIHelpers.CloseAllDialogs();

await Task.Delay(500);

Expand Down
Loading