From 588aa25822cec1aa0249c6b5309f5723d2059c3c Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Mon, 23 Nov 2020 00:00:04 -0500 Subject: [PATCH] feat(desktop): add configurable notifications --- XIVChat Desktop Installer/Product.wxs | 63 +++++++----- XIVChat Desktop/App.xaml.cs | 43 +++++++- XIVChat Desktop/ConfigWindow.xaml | 36 +++++++ XIVChat Desktop/ConfigWindow.xaml.cs | 30 ++++++ XIVChat Desktop/Configuration.cs | 69 +++++++++++++ XIVChat Desktop/Connection.cs | 5 + XIVChat Desktop/Controls/MessageTextBlock.cs | 10 +- XIVChat Desktop/Export.xaml.cs | 3 + XIVChat Desktop/ManageNotification.xaml | 103 +++++++++++++++++++ XIVChat Desktop/Notifications.cs | 21 ++++ XIVChat Desktop/Util.cs | 63 ++++++++++++ XIVChat Desktop/XIVChat Desktop.csproj | 1 + XIVChatCommon/Message/Message.cs | 88 ++++++++++++++++ 13 files changed, 506 insertions(+), 29 deletions(-) create mode 100644 XIVChat Desktop/ManageNotification.xaml create mode 100644 XIVChat Desktop/Notifications.cs diff --git a/XIVChat Desktop Installer/Product.wxs b/XIVChat Desktop Installer/Product.wxs index a5e2e9f..2e54342 100644 --- a/XIVChat Desktop Installer/Product.wxs +++ b/XIVChat Desktop Installer/Product.wxs @@ -1,33 +1,44 @@ - - + + - - + + - - - - - + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + diff --git a/XIVChat Desktop/App.xaml.cs b/XIVChat Desktop/App.xaml.cs index 4e5f202..6ee07e6 100644 --- a/XIVChat Desktop/App.xaml.cs +++ b/XIVChat Desktop/App.xaml.cs @@ -1,12 +1,18 @@ using System; using System.ComponentModel; using System.Globalization; +using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Markup; +using Windows.UI.Notifications; +using Microsoft.Toolkit.Uwp.Notifications; using ModernWpf; +using XIVChatCommon.Message; +using XIVChatCommon.Message.Server; -// TODO: key word notification, notifications on message type, targeted message (like emote targeting you) +// TODO: search messages +// TODO: notifications for targeted messages (like emote targeting you) namespace XIVChat_Desktop { /// @@ -34,6 +40,8 @@ namespace XIVChat_Desktop { public event PropertyChangedEventHandler? PropertyChanged; private async void Application_Startup(object sender, StartupEventArgs e) { + Notifications.Initialise(); + try { this.Config = Configuration.Load() ?? new Configuration(); } catch (Exception ex) { @@ -121,6 +129,7 @@ namespace XIVChat_Desktop { } this.Connection = new Connection(this, host, port); + this.Connection.ReceiveMessage += this.OnReceiveMessage; Task.Run(this.Connection.Connect); } @@ -132,5 +141,37 @@ namespace XIVChat_Desktop { this.Connection?.Disconnect(); this.Connection = null; } + + private void OnReceiveMessage(ServerMessage message) { + if (!this.Config.Notifications.Any(notif => notif.Matches(message))) { + return; + } + + var sender = message.GetSenderPlayer(); + + var builder = new ToastContentBuilder(); + + if (sender != null) { + var name = sender.Name; + + if (sender.Server != 0) { + name += $" ({Util.WorldName(sender.Server)})"; + } + + builder.AddText(name); + } else { + builder.AddText("Notification"); + } + + builder + .AddText(message.ContentText) + .AddAttributionText(message.Channel.Name()); + + var content = builder.GetToastContent(); + + var toast = new ToastNotification(content.GetXml()); + + DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); + } } } diff --git a/XIVChat Desktop/ConfigWindow.xaml b/XIVChat Desktop/ConfigWindow.xaml index a5caf7e..71ff8e4 100644 --- a/XIVChat Desktop/ConfigWindow.xaml +++ b/XIVChat Desktop/ConfigWindow.xaml @@ -84,5 +84,41 @@ + + + + + + + + + + + + + + + + +