Skip to content

Commit 2c0b7e0

Browse files
committed
Update tile on message
Only when in background. Still does not update when app is suspended.
1 parent 3e5298d commit 2c0b7e0

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

Signal-Windows/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Windows.UI.Xaml.Controls;
1414
using Windows.UI.Xaml.Navigation;
1515
using Microsoft.QueryStringDotNET;
16+
using Windows.UI.Notifications;
1617

1718
namespace Signal_Windows
1819
{
@@ -139,6 +140,7 @@ private async Task OnLaunchedOrActivated(IActivatedEventArgs e, bool launched =
139140
}
140141
}
141142
}
143+
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
142144
// Sicherstellen, dass das aktuelle Fenster aktiv ist
143145
Window.Current.Activate();
144146
}

Signal-Windows/Signal/IncomingMessages.cs

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ private void HandleSignalMessage(SignalServiceEnvelope envelope, SignalServiceCo
426426
Debug.WriteLine("received message: " + message.Content);
427427
if (!App.WindowActive)
428428
{
429+
SendTileNotification(message);
429430
SendMessageNotification(message);
430431
}
431432
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
@@ -449,17 +450,12 @@ private void SendMessageNotification(SignalMessage message)
449450
HintCrop = ToastGenericAppLogoCrop.Circle
450451
}
451452
};
452-
AdaptiveText title = new AdaptiveText()
453-
{
454-
Text = message.Author.ThreadDisplayName,
455-
HintMaxLines = 1
456-
};
457-
AdaptiveText messageText = new AdaptiveText()
453+
454+
var notificationText = GetNotificationText(message);
455+
foreach (var item in notificationText)
458456
{
459-
Text = message.Content.Content
460-
};
461-
toastBinding.Children.Add(title);
462-
toastBinding.Children.Add(messageText);
457+
toastBinding.Children.Add(item);
458+
}
463459

464460
ToastContent toastContent = new ToastContent()
465461
{
@@ -479,5 +475,61 @@ private void SendMessageNotification(SignalMessage message)
479475
toastNotification.Tag = notificationId;
480476
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
481477
}
478+
479+
private void SendTileNotification(SignalMessage message)
480+
{
481+
TileBindingContentAdaptive tileBindingContent = new TileBindingContentAdaptive()
482+
{
483+
PeekImage = new TilePeekImage()
484+
{
485+
Source = "ms-appx:///Assets/gambino.png"
486+
}
487+
};
488+
var notificationText = GetNotificationText(message);
489+
foreach (var item in notificationText)
490+
{
491+
tileBindingContent.Children.Add(item);
492+
}
493+
494+
TileBinding tileBinding = new TileBinding()
495+
{
496+
Content = tileBindingContent
497+
};
498+
499+
TileContent tileContent = new TileContent()
500+
{
501+
Visual = new TileVisual()
502+
{
503+
TileMedium = tileBinding,
504+
TileWide = tileBinding,
505+
TileLarge = tileBinding
506+
}
507+
};
508+
509+
TileNotification tileNotification = new TileNotification(tileContent.GetXml());
510+
if (message.Author.ExpiresInSeconds > 0)
511+
{
512+
tileNotification.ExpirationTime = DateTime.Now.Add(TimeSpan.FromSeconds(message.Author.ExpiresInSeconds));
513+
}
514+
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
515+
}
516+
517+
private IList<AdaptiveText> GetNotificationText(SignalMessage message)
518+
{
519+
List<AdaptiveText> text = new List<AdaptiveText>();
520+
AdaptiveText title = new AdaptiveText()
521+
{
522+
Text = message.Author.ThreadDisplayName,
523+
HintMaxLines = 1
524+
};
525+
AdaptiveText messageText = new AdaptiveText()
526+
{
527+
Text = message.Content.Content,
528+
HintWrap = true
529+
};
530+
text.Add(title);
531+
text.Add(messageText);
532+
return text;
533+
}
482534
}
483535
}

0 commit comments

Comments
 (0)