@@ -337,13 +337,13 @@ public static void SaveSessionTabs() // Enumerates through all tabs and gets the
337
337
}
338
338
339
339
// Occurs when an exception is not handled on the UI thread.
340
- private static void OnUnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs e ) => AppUnhandledException ( e . Exception ) ;
340
+ private static void OnUnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs e ) => AppUnhandledException ( e . Exception , true ) ;
341
341
342
342
// Occurs when an exception is not handled on a background thread.
343
343
// ie. A task is fired and forgotten Task.Run(() => {...})
344
- private static void OnUnobservedException ( object sender , UnobservedTaskExceptionEventArgs e ) => AppUnhandledException ( e . Exception ) ;
344
+ private static void OnUnobservedException ( object sender , UnobservedTaskExceptionEventArgs e ) => AppUnhandledException ( e . Exception , false ) ;
345
345
346
- private static void AppUnhandledException ( Exception ex )
346
+ private static void AppUnhandledException ( Exception ex , bool shouldShowNotification )
347
347
{
348
348
StringBuilder formattedException = new StringBuilder ( ) { Capacity = 200 } ;
349
349
@@ -385,49 +385,50 @@ private static void AppUnhandledException(Exception ex)
385
385
386
386
SaveSessionTabs ( ) ;
387
387
Logger . UnhandledError ( ex , ex . Message ) ;
388
- if ( ShowErrorNotification )
388
+
389
+ if ( ! ShowErrorNotification || ! shouldShowNotification )
390
+ return ;
391
+
392
+ var toastContent = new ToastContent ( )
389
393
{
390
- var toastContent = new ToastContent ( )
394
+ Visual = new ToastVisual ( )
391
395
{
392
- Visual = new ToastVisual ( )
396
+ BindingGeneric = new ToastBindingGeneric ( )
393
397
{
394
- BindingGeneric = new ToastBindingGeneric ( )
398
+ Children =
395
399
{
396
- Children =
400
+ new AdaptiveText ( )
397
401
{
398
- new AdaptiveText ( )
399
- {
400
- Text = "ExceptionNotificationHeader" . GetLocalizedResource ( )
401
- } ,
402
- new AdaptiveText ( )
403
- {
404
- Text = "ExceptionNotificationBody" . GetLocalizedResource ( )
405
- }
402
+ Text = "ExceptionNotificationHeader" . GetLocalizedResource ( )
406
403
} ,
407
- AppLogoOverride = new ToastGenericAppLogo ( )
404
+ new AdaptiveText ( )
408
405
{
409
- Source = "ms-appx:///Assets/error.png"
406
+ Text = "ExceptionNotificationBody" . GetLocalizedResource ( )
410
407
}
408
+ } ,
409
+ AppLogoOverride = new ToastGenericAppLogo ( )
410
+ {
411
+ Source = "ms-appx:///Assets/error.png"
411
412
}
412
- } ,
413
- Actions = new ToastActionsCustom ( )
413
+ }
414
+ } ,
415
+ Actions = new ToastActionsCustom ( )
416
+ {
417
+ Buttons =
414
418
{
415
- Buttons =
419
+ new ToastButton ( "ExceptionNotificationReportButton" . GetLocalizedResource ( ) , "report" )
416
420
{
417
- new ToastButton ( "ExceptionNotificationReportButton" . GetLocalizedResource ( ) , "report" )
418
- {
419
- ActivationType = ToastActivationType . Foreground
420
- }
421
+ ActivationType = ToastActivationType . Foreground
421
422
}
422
423
}
423
- } ;
424
+ }
425
+ } ;
424
426
425
- // Create the toast notification
426
- var toastNotif = new ToastNotification ( toastContent . GetXml ( ) ) ;
427
+ // Create the toast notification
428
+ var toastNotif = new ToastNotification ( toastContent . GetXml ( ) ) ;
427
429
428
- // And send the notification
429
- ToastNotificationManager . CreateToastNotifier ( ) . Show ( toastNotif ) ;
430
- }
430
+ // And send the notification
431
+ ToastNotificationManager . CreateToastNotifier ( ) . Show ( toastNotif ) ;
431
432
}
432
433
433
434
public static void CloseApp ( )
0 commit comments