Skip to content

Commit

Permalink
Block subsequent close clicks while handling the exit
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Mar 12, 2023
1 parent cdd6a88 commit bb29ff0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Amethyst/Classes/Interfacing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static class Interfacing

public static bool
IsExitingNow, // App closing check
IsExitHandled; // If actions have been done
IsExitHandled, // If actions have been done
IsExitPending; // If actions are running

public static readonly object UpdateLock = new();

Expand Down
8 changes: 8 additions & 0 deletions Amethyst/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,8 @@ private async void Window_Closed(object sender, WindowEventArgs args)
// and Handled(false) means Continue()
// -> Block exiting until we're done
args.Handled = true;

if (Interfacing.IsExitPending) return;
switch (Interfacing.IsExitHandled)
{
// Show the close tip (if not shown yet)
Expand All @@ -1870,6 +1872,9 @@ private async void Window_Closed(object sender, WindowEventArgs args)
// Handle all the exit actions (if needed)
case false:
{
// Mark as handled
Interfacing.IsExitPending = true;

// Hide the update bar now
UpdateInfoBar.IsOpen = false;
UpdateInfoBar.Opacity = 0.0;
Expand All @@ -1878,6 +1883,9 @@ private async void Window_Closed(object sender, WindowEventArgs args)
// Run shutdown tasks
await ShutdownController.ExecuteAllTasks();

// Mark as mostly done
Interfacing.IsExitPending = true;

// Make sure any Mica/Acrylic controller is disposed so it doesn't try to
// use this closed window.
if (_micaController is not null)
Expand Down

0 comments on commit bb29ff0

Please sign in to comment.