1717using DevHome . Views ;
1818using Microsoft . Extensions . DependencyInjection ;
1919using Microsoft . Extensions . Hosting ;
20+ using Microsoft . UI . Dispatching ;
2021using Microsoft . UI . Xaml ;
22+ using Microsoft . Windows . AppLifecycle ;
2123
2224namespace DevHome ;
2325
2426// To learn more about WinUI 3, see https://docs.microsoft.com/windows/apps/winui/winui3/.
2527public partial class App : Application , IApp
2628{
29+ private readonly DispatcherQueue _dispatcherQueue ;
30+
2731 // The .NET Generic Host provides dependency injection, configuration, logging, and other services.
2832 // https://docs.microsoft.com/dotnet/core/extensions/generic-host
2933 // https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
@@ -44,16 +48,18 @@ public T GetService<T>()
4448 public App ( )
4549 {
4650 InitializeComponent ( ) ;
51+ _dispatcherQueue = DispatcherQueue . GetForCurrentThread ( ) ;
4752
4853 Host = Microsoft . Extensions . Hosting . Host .
4954 CreateDefaultBuilder ( ) .
5055 UseContentRoot ( AppContext . BaseDirectory ) .
5156 ConfigureServices ( ( context , services ) =>
5257 {
5358 // Default Activation Handler
54- services . AddTransient < ActivationHandler < LaunchActivatedEventArgs > , DefaultActivationHandler > ( ) ;
59+ services . AddTransient < ActivationHandler < Microsoft . UI . Xaml . LaunchActivatedEventArgs > , DefaultActivationHandler > ( ) ;
5560
5661 // Other Activation Handlers
62+ services . AddTransient < IActivationHandler , ProtocolActivationHandler > ( ) ;
5763
5864 // Services
5965 services . AddSingleton < ILocalSettingsService , LocalSettingsService > ( ) ;
@@ -97,6 +103,7 @@ public App()
97103 Build ( ) ;
98104
99105 UnhandledException += App_UnhandledException ;
106+ AppInstance . GetCurrent ( ) . Activated += OnActivated ;
100107 }
101108
102109 private async void App_UnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs e )
@@ -106,11 +113,19 @@ private async void App_UnhandledException(object sender, Microsoft.UI.Xaml.Unhan
106113 await GetService < IPluginService > ( ) . SignalStopPluginsAsync ( ) ;
107114 }
108115
109- protected async override void OnLaunched ( LaunchActivatedEventArgs args )
116+ protected async override void OnLaunched ( Microsoft . UI . Xaml . LaunchActivatedEventArgs args )
110117 {
111118 base . OnLaunched ( args ) ;
112119
113- await GetService < IActivationService > ( ) . ActivateAsync ( args ) ;
120+ await GetService < IActivationService > ( ) . ActivateAsync ( AppInstance . GetCurrent ( ) . GetActivatedEventArgs ( ) . Data ) ;
114121 await GetService < IAccountsService > ( ) . InitializeAsync ( ) ;
115122 }
123+
124+ private void OnActivated ( object ? sender , AppActivationArguments args )
125+ {
126+ _dispatcherQueue . TryEnqueue ( async ( ) =>
127+ {
128+ await GetService < IActivationService > ( ) . ActivateAsync ( args . Data ) ;
129+ } ) ;
130+ }
116131}
0 commit comments