Skip to content

Commit

Permalink
Update DialogService.cs to show windows NOT as dialogs, so you can in…
Browse files Browse the repository at this point in the history
…teract with multiple Chat-Prisma windows at once
  • Loading branch information
haefele committed Nov 17, 2023
1 parent c7a9deb commit ae245ac
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/ChatPrisma/Services/Dialogs/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public class DialogService(IServiceProvider serviceProvider, IOptionsMonitor<App
FallbackValue = applicationOptions.CurrentValue.ApplicationName,
});

if (viewModel is ICloseWindow closeWindow)
{
closeWindow.Close += (_, e) =>
{
// This automatically closes the window
window.DialogResult = e.DialogResult;
};
}

if (viewModel is IConfigureWindow configureWindow)
{
configureWindow.Configure(window);
Expand All @@ -51,10 +42,25 @@ public class DialogService(IServiceProvider serviceProvider, IOptionsMonitor<App
await initialize.InitializeAsync();
}

// Need an await for the caller to yield
await Task.Yield();
TaskCompletionSource<bool?> showDialogTaskCompletionSource = new();

if (viewModel is ICloseWindow closeWindow)
{
closeWindow.Close += (_, e) =>
{
showDialogTaskCompletionSource.TrySetResult(e.DialogResult);
window.Close();
};
}

window.Closed += (_, _) =>
{
showDialogTaskCompletionSource.TrySetResult(null);
};

window.Show();

var result = window.ShowDialog();
var result = await showDialogTaskCompletionSource.Task;

if (viewModel is IFinalize finalize)
{
Expand Down

0 comments on commit ae245ac

Please sign in to comment.