@@ -189,7 +189,7 @@ private void LaunchAndBringToForegroundIfNeeded()
189
189
m_window .Activate ();
190
190
191
191
// Additionally we show using our helper, since if activated via a app notification, it doesn't
192
- // activate the window correctly
192
+ // activate the window correctly.
193
193
WindowHelper .ShowWindow (m_window );
194
194
}
195
195
else
@@ -205,37 +205,43 @@ private void NotificationManager_NotificationInvoked(AppNotificationManager send
205
205
206
206
private void HandleNotification (AppNotificationActivatedEventArgs args )
207
207
{
208
- // Use the dispatcher from the window if present, otherwise the app dispatcher
208
+ // Use the dispatcher from the window if present, otherwise the app dispatcher.
209
209
var dispatcherQueue = m_window ? .DispatcherQueue ?? DispatcherQueue .GetForCurrentThread ();
210
210
211
211
212
212
dispatcherQueue .TryEnqueue (async delegate
213
213
{
214
-
215
- switch (args .Arguments [" action" ])
214
+ if (args .Argument .Contains (" action" ))
216
215
{
217
- // Send a background message
218
- case " sendMessage" :
219
- string message = args .UserInput [" textBox" ].ToString ();
220
- // TODO: Send it
221
-
222
- // If the UI app isn't open
223
- if (m_window == null )
224
- {
225
- // Close since we're done
226
- Process .GetCurrentProcess ().Kill ();
227
- }
228
-
229
- break ;
230
-
231
- // View a message
232
- case " viewMessage" :
233
-
234
- // Launch/bring window to foreground
235
- LaunchAndBringToForegroundIfNeeded ();
236
-
237
- // TODO: Open the message
238
- break ;
216
+ switch (args .Arguments [" action" ])
217
+ {
218
+ // Send a background message.
219
+ case " sendMessage" :
220
+ string message = args .UserInput [" textBox" ].ToString ();
221
+ // TODO: Send it.
222
+
223
+ // If the UI app isn't open.
224
+ if (m_window == null )
225
+ {
226
+ // Close since we're done.
227
+ Process .GetCurrentProcess ().Kill ();
228
+ }
229
+
230
+ break ;
231
+
232
+ // View a message.
233
+ case " viewMessage" :
234
+
235
+ // Launch/bring window to foreground.
236
+ LaunchAndBringToForegroundIfNeeded ();
237
+
238
+ // TODO: Open the message.
239
+ break ;
240
+ }
241
+ }
242
+ else
243
+ {
244
+ Debug .Print (" Notification args is null" );
239
245
}
240
246
});
241
247
}
@@ -281,14 +287,14 @@ public static DispatcherQueue DispatcherQueue { get; private set; }
281
287
282
288
protected override void OnLaunched (Microsoft .UI .Xaml .LaunchActivatedEventArgs args )
283
289
{
284
- // Get the app-level dispatcher
290
+ // Get the app-level dispatcher.
285
291
DispatcherQueue = global :: Microsoft .UI .Dispatching .DispatcherQueue .GetForCurrentThread ();
286
292
287
- // Register for toast activation. Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater
293
+ // Register for toast activation. Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater.
288
294
ToastNotificationManagerCompat .OnActivated += ToastNotificationManagerCompat_OnActivated ;
289
295
290
296
// If we weren't launched by an app, launch our window like normal.
291
- // Otherwise if launched by a toast, our OnActivated callback will be triggered
297
+ // Otherwise if launched by a toast, our OnActivated callback will be triggered.
292
298
if (! ToastNotificationManagerCompat .WasCurrentProcessToastActivated ())
293
299
{
294
300
LaunchAndBringToForegroundIfNeeded ();
@@ -303,7 +309,7 @@ private void LaunchAndBringToForegroundIfNeeded()
303
309
m_window .Activate ();
304
310
305
311
// Additionally we show using our helper, since if activated via a toast, it doesn't
306
- // activate the window correctly
312
+ // activate the window correctly.
307
313
WindowHelper .ShowWindow (m_window );
308
314
}
309
315
else
@@ -314,7 +320,7 @@ private void LaunchAndBringToForegroundIfNeeded()
314
320
315
321
private void ToastNotificationManagerCompat_OnActivated (ToastNotificationActivatedEventArgsCompat e )
316
322
{
317
- // Use the dispatcher from the window if present, otherwise the app dispatcher
323
+ // Use the dispatcher from the window if present, otherwise the app dispatcher.
318
324
var dispatcherQueue = m_window ? .DispatcherQueue ?? App .DispatcherQueue ;
319
325
320
326
dispatcherQueue .TryEnqueue (delegate
@@ -323,27 +329,27 @@ private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivat
323
329
324
330
switch (args [" action" ])
325
331
{
326
- // Send a background message
332
+ // Send a background message.
327
333
case " sendMessage" :
328
334
string message = e .UserInput [" textBox" ].ToString ();
329
- // TODO: Send it
335
+ // TODO: Send it.
330
336
331
- // If the UI app isn't open
337
+ // If the UI app isn't open.
332
338
if (m_window == null )
333
339
{
334
- // Close since we're done
340
+ // Close since we're done.
335
341
Process .GetCurrentProcess ().Kill ();
336
342
}
337
343
338
344
break ;
339
345
340
- // View a message
346
+ // View a message.
341
347
case " viewMessage" :
342
348
343
- // Launch/bring window to foreground
349
+ // Launch/bring window to foreground.
344
350
LaunchAndBringToForegroundIfNeeded ();
345
351
346
- // TODO: Open the message
352
+ // TODO: Open the message.
347
353
break ;
348
354
}
349
355
});
0 commit comments