Skip to content

Commit

Permalink
Add workaround to ensure exit works
Browse files Browse the repository at this point in the history
  • Loading branch information
josetr committed Nov 10, 2022
1 parent 772d3bc commit d7aeb5d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/AudioDeviceSwitcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace AudioDeviceSwitcher;
using Activation = Windows.ApplicationModel.Activation;
using PInvoke;
using Microsoft.UI.Xaml.Controls;
using System.Reflection.Metadata.Ecma335;

public sealed partial class App : Application, IApp
{
Expand Down Expand Up @@ -57,7 +58,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
User32.MessageBox(IntPtr.Zero, e.Message, AudioSwitcherState.Title, User32.MessageBoxOptions.MB_ICONERROR);
}

Exit();
ExitNow();
return;
}

Expand All @@ -67,7 +68,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
Kernel32.GetLastError() == Win32ErrorCode.ERROR_ACCESS_DENIED)
{
DesktopWindow.BroadcastRestore();
Exit();
ExitNow();
return;
}

Expand All @@ -82,6 +83,13 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
_window.RunInBackround();
else
_window.Activate();

// TODO: Remove workaround once Application.Exit() gets fixed
// See https://github.com/microsoft/microsoft-ui-xaml/issues/5931
static void ExitNow()
{
Environment.Exit(0);
}
}

private static IServiceProvider ConfigureServices()
Expand Down

0 comments on commit d7aeb5d

Please sign in to comment.