@@ -24,7 +24,7 @@ public sealed class SignalBackgroundTask : IBackgroundTask
2424 private BackgroundTaskDeferral Deferral ;
2525 private SignalLibHandle Handle ;
2626 private ToastNotifier ToastNotifier ;
27- private AutoResetEvent e = new AutoResetEvent ( false ) ;
27+ private AutoResetEvent ResetEvent = new AutoResetEvent ( false ) ;
2828
2929 public void Run ( IBackgroundTaskInstance taskInstance )
3030 {
@@ -47,7 +47,7 @@ public void Run(IBackgroundTaskInstance taskInstance)
4747 Handle = new SignalLibHandle ( true ) ;
4848 Handle . SignalMessageEvent += Handle_SignalMessageEvent ;
4949 Handle . BackgroundAcquire ( ) ;
50- e . WaitOne ( ) ;
50+ ResetEvent . WaitOne ( ) ;
5151 }
5252 catch ( Exception e )
5353 {
@@ -65,38 +65,46 @@ public void Run(IBackgroundTaskInstance taskInstance)
6565 private void OnCanceled ( IBackgroundTaskInstance sender , BackgroundTaskCancellationReason reason )
6666 {
6767 Logger . LogInformation ( "Background task received cancel request" ) ;
68- e . Set ( ) ;
68+ ResetEvent . Set ( ) ;
6969 }
7070
7171 private void Handle_SignalMessageEvent ( object sender , SignalMessageEventArgs e )
7272 {
73- string notificationId = e . Message . ThreadId ;
74- ToastBindingGeneric toastBinding = new ToastBindingGeneric ( ) ;
75-
76- var notificationText = GetNotificationText ( e . Message . Author . ThreadDisplayName , e . Message . Content . Content ) ;
77- foreach ( var item in notificationText )
73+ if ( e . MessageType == Lib . Events . SignalMessageType . NormalMessage )
7874 {
79- toastBinding . Children . Add ( item ) ;
80- }
75+ string notificationId = e . Message . ThreadId ;
76+ ToastBindingGeneric toastBinding = new ToastBindingGeneric ( ) ;
8177
82- ToastContent toastContent = new ToastContent ( )
83- {
84- Launch = notificationId ,
85- Visual = new ToastVisual ( )
78+ var notificationText = GetNotificationText ( e . Message . Author . ThreadDisplayName , e . Message . Content . Content ) ;
79+ foreach ( var item in notificationText )
8680 {
87- BindingGeneric = toastBinding
88- } ,
89- DisplayTimestamp = DateTimeOffset . FromUnixTimeMilliseconds ( e . Message . ReceivedTimestamp )
90- } ;
81+ toastBinding . Children . Add ( item ) ;
82+ }
9183
92- ToastNotification toastNotification = new ToastNotification ( toastContent . GetXml ( ) ) ;
93- uint expiresIn = e . Message . ExpiresAt ;
94- if ( expiresIn > 0 )
84+ ToastContent toastContent = new ToastContent ( )
85+ {
86+ Launch = notificationId ,
87+ Visual = new ToastVisual ( )
88+ {
89+ BindingGeneric = toastBinding
90+ } ,
91+ DisplayTimestamp = DateTimeOffset . FromUnixTimeMilliseconds ( e . Message . ReceivedTimestamp )
92+ } ;
93+
94+ ToastNotification toastNotification = new ToastNotification ( toastContent . GetXml ( ) ) ;
95+ uint expiresIn = e . Message . ExpiresAt ;
96+ if ( expiresIn > 0 )
97+ {
98+ toastNotification . ExpirationTime = DateTime . Now . Add ( TimeSpan . FromSeconds ( expiresIn ) ) ;
99+ }
100+ toastNotification . Tag = notificationId ;
101+ ToastNotifier . Show ( toastNotification ) ;
102+ }
103+ else if ( e . MessageType == Lib . Events . SignalMessageType . PipeEmptyMessage )
95104 {
96- toastNotification . ExpirationTime = DateTime . Now . Add ( TimeSpan . FromSeconds ( expiresIn ) ) ;
105+ Logger . LogInformation ( "Background task has drained the pipe" ) ;
106+ ResetEvent . Set ( ) ;
97107 }
98- toastNotification . Tag = notificationId ;
99- ToastNotifier . Show ( toastNotification ) ;
100108 }
101109
102110 private IList < AdaptiveText > GetNotificationText ( string authorName , string content )
0 commit comments